Skip to content

Add support for a data url file loader with application/esbuild builders #30391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
imirkin opened this issue May 27, 2025 · 5 comments
Open
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

Comments

@imirkin
Copy link

imirkin commented May 27, 2025

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 like data: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.

@alan-agius4
Copy link
Collaborator

You can use the loader option to achieve the same thing.

      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "loader": {
              ".ico": "text" // Can also be "binary", "file", "empty",
            }

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2025
@imirkin
Copy link
Author

imirkin commented May 27, 2025 via email

@alan-agius4
Copy link
Collaborator

Sorry for misunderstanding this. You are right the text loader will not generate data url. See: https://esbuild.github.io/content-types/#text

@alan-agius4 alan-agius4 reopened this May 27, 2025
@imirkin
Copy link
Author

imirkin commented May 27, 2025 via email

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label May 28, 2025
Copy link
Contributor

angular-robot bot commented May 28, 2025

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants