Skip to content

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

Description

@imirkin

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.

Activity

  1. alan-agius4 commented on May 27, 2025

    @alan-agius4
    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",
                }
    
  2. imirkin commented on May 27, 2025

    @imirkin
    ContributorAuthor
  3. added
    feature
    on May 27, 2025
  4. alan-agius4 commented on May 27, 2025

    @alan-agius4
    Collaborator

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

  5. imirkin commented on May 27, 2025

    @imirkin
    ContributorAuthor
  6. added
    feature: votes required
    on May 28, 2025
  7. angular-robot commented on May 28, 2025

    @angular-robot
    Contributor

    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.

  8. added 3 commits that reference this issue on May 30, 2025
    2ae5328
    8bb46cd
    2f7b262
  9. added a commit that references this issue on Jun 3, 2025
    8f305ef
  10. angular-automatic-lock-bot commented on Jul 4, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  11. locked and limited conversation to collaborators on Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    angular/build:applicationarea: @angular/buildfeaturefeature: votes required

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions