url-loader icon indicating copy to clipboard operation
url-loader copied to clipboard

option to prefix URLs with `file://`

Open trusktr opened this issue 5 years ago • 3 comments

  • Operating System: N/A
  • Node Version: N/A
  • NPM Version: N/A
  • webpack Version: N/A
  • url-loader Version: 4

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 avatar Jun 19 '20 01:06 trusktr

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

trusktr avatar Jun 19 '20 01:06 trusktr

Yes, for custom generation you can use generator

alexander-akait avatar Jun 19 '20 14:06 alexander-akait

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

alexander-akait avatar Jun 19 '20 14:06 alexander-akait