Add support for a data url file loader with application/esbuild builders #30391
Labels
angular/build:application
area: @angular/build
feature: votes required
Feature request which is currently still in the voting phase
feature
Issue that requests a new feature
Command
build
Description
This describes 4 loader schemes: text, binary, file, and empty.
My use-case is to switch up the contents of the favicon, which I do by updating the href of the relevant
<link rel="icon">
. This is simplest way to do that is with a data url (updating it with a real URL would cause it to have to be loaded separately, which works, but requires an extra request).With the webpack loader, this is easily achieved with e.g.
import favicon from "!!url-loader!favicon.ico";
which produces a string likedata:image/x-icon;base64,....
.Describe the solution you'd like
Add a "data-url" (or "url" or "data") loader with the following import parameters:
mime: string
(defaults to mime type based on extension)plain: boolean
(defaults to false, controls whether base64 is enabled)So e.g. one could do
import contents from 'foo.svg' with {loader: 'data-url', mime: 'foo/bar', plain: true}
Perhaps better names for the parameters could be found, e.g. the mime type isn't technically a mime type and can take additional parameters, e.g.
text/plain;charset=utf-8
and so on.Describe alternatives you've considered
Without this, the options seem to be to do this computation at runtime, e.g.:
URL.createObjectURL(new Blob([uint8array], {type: mimetype}))
"data:" + mimetype + ";base64," + btoa(uint8array).replace(/\+/g, '-').replace(/\//g, '_')
(untested, but something like that should work)This works, but why not have something in the framework that does the thing you want for you, and you don't have to do these fixups each time one wants to import such an asset.
The text was updated successfully, but these errors were encountered: