Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Add ability to set encodings #25

Closed
@kisenka

Description

@kisenka

Hi @sokra!
Thanks for the great loader.

Default loader behaviour is to encode source and return Data URI. But for SVG is no necessary to encode source in base64, because it works with raw content encoded with encodeURIComponent. Moreover it will decrease ~30% of content length and save browser resources for unpacking base64 string. My suggestion is to add user defined handlers to specific mime-type, something like this:

{
  module: {
    loaders: [
      {
        test: /\.(jpg|png|gif|svg)$/
        loader: 'url?limit=10000'
      }
    ]
  },
  url: {
    handlers: {
      'image/svg+xml': function (content) {
        return 'data:image/svg+xml,' + encodeURIComponent(content);
      }
    }
  }
}

For backward compatibility option can be disabled by default. For details please take a look at my advanced-url-loader which based on url-loader. I can make a PR, if you agree. Also I want be a volunteer and cover all existing loader code with tests. And close some issues.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions