Fix css-loader's resolving of /path/to/file
type URLs
#240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a 🐛 bug fix.
Summary
Previous versions (3.x) of Webpack's
css-loader
wouldn't cause any problems if the file referenced in a stylesheet'surl(…)
was using a server-relative URL (aka/path/to/file.jpg
). 4.x and beyond changed it so Webpack always tries to resolve the url within its own context. That doesn't work for us due to cases where/images/file.png
should be loaded normally from the website's public folder (akasrc
), rather than pulled from somewhere in Webpack'sfrontend
context.This change makes it so if you use truly relative paths like
./something.jpg
or even../something/else.jpg
, that will get resolved through Webpack (and in fact I've addedfile-loader
support for images via Webpack now)…but any path starting with a slash now reverts to a passthrough so the browser can load that static file directly out of the site source.TODO: Now that we actually do have image file support within Webpack, we could in theory locate images in
frontend
, rather thansrc
, add import statements in either CSS or JS files, and then reference those with a Liquid tag/Ruby helper now that those files are in the Webpack manifest. It would then work similarly to Rails' Webpacker image tag support. A project for another day…Fixes #239