cheton / browserify-css

A Browserify transform for bundling, rebasing, inlining, and minifying CSS files.
http://cheton.github.io/browserify-css/
MIT License
144 stars 22 forks source link

Example doesn't copy font and image files from node_modules #59

Closed localjo closed 6 years ago

localjo commented 6 years ago

In the example for how to load font and image files from node_modules, the paths in bootstrap.css begin with ../fonts/ not with ../node_modules so the files don't seem to get copied.

I'm running into this issue with font-awesome, which also has relative URLs in the CSS file;

url('../fonts/fontawesome-webfont.eot?v=4.7.0');

I think, at least, the example code should be updated to check for paths that start with ../fonts, but I also think that's less than ideal, since that prefix isn't as unique as ../node_modules, so there could be matches with non-vendor files as well.

I think there should be a way to only apply the processRelativeUrl function to relative URLs that are contained in files within the node_modules directory. In other words, I think checking what the relative URL starts with is the wrong test, since files in node_modules often have relative URLs that do not start with node_modules.

Are there any easy ways to resolve relative URLs relative to the file they are included in, like CSS does by default? I've tried setting rebaseUrls: false which works partially, but then all URLs are resolved relative to the CSS bundle, rather than the @imported files that they originate in.

localjo commented 6 years ago

Oops, I was running the wrong code. Turns out the example code does work. Sorry for the noise. 🙈