webpack-contrib / url-loader

A loader for webpack which transforms files into base64 URIs
MIT License
1.41k stars 158 forks source link

option to prefix URLs with `file://` #215

Open trusktr opened 4 years ago

trusktr commented 4 years ago

Feature Proposal

Maybe something like

fileUrl: true

Feature Use Case

Allows URLs to be imported as file:// URLs. Currently we get an absolute path in the file system when the file is above the limit. In some cases (f.e. NW.js or Electron) it would be simple if the path included file:// so that it works fine with web APIs out of the box.

F.e., instead of

import * as svgUrl from './some.svg'
<img src={"file://" + svgUrl} />

we could write

import * as svgUrl from './some.svg'
<img src={svgUrl} />

which makes the code more portable.

trusktr commented 4 years ago

Oh, I suppose I can use the generator option to return any type or URL that I want?

alexander-akait commented 4 years ago

Yes, for custom generation you can use generator

alexander-akait commented 4 years ago

You can send a PR to docs how to achieve it for other developers