babel-plugin-file-loader
babel-plugin-file-loader copied to clipboard
Use node's resolve system
It seemed unintuitive that an import
would have to point to a relative path and isn't processed by node's module loading system (i.e. check node_modules
, etc). Perhaps that because I was expecting the same behavior as webpacks file-loader.
In any case, is that something that can be added?
It should behave the same as the webpack loader. I'm experiencing the same bug. I will try to push PR for this one asap.
A way to reproduce issue would be nice
Please modify example
project in this repository so it reproduces this issue
@nickpalmer please tell me your commit is found somewhere on npm 👯♀️
@sheerun please consider his commit. thanks.
If you import an SVG from node_modules
let's say from boxicons like this.
import alarm from 'boxicons/svg/regular/bx-alarm.svg';
export default function Hello(props) {
return (
<div>
<img src={alarm} />
</div>
);
}
You will get an error like this.
SyntaxError: [file name]: File does not exist
This is because the plugin will look for the file in [CWD]/boxicons/svg/regular/bx-alarm.svg
and not in [CWD]/node_modules/boxicons/svg/regular/bx-alarm.svg
.
Conventionally, if someone were intending to use an SVG from their project they should use ./folder/something.svg
rather than folder/something.svg
as this implies that there would be a folder called folder
in node_modules
.
This is why this commit submitted by @nickpalmer would work.
I looked around for other alternatives and your package is probably the best one to date with the exception for this small quirk. Do let me know if you need further clarifications or if you would like me to submit a working PR.
@cblanquera hello! im assuming youre using this babel plugin to server side render the assets created from Webpack's file-loader
if im wrong, no need to answer
but if yes, what version of Webpack and file loader are u running? ideally Wp5 and latest version of file loader is what im looking for
unfortunately, I get the feeling that this package isnt maintained anymore