Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix css-loader's resolving of /path/to/file type URLs #240

Merged
merged 6 commits into from
Feb 11, 2021

Conversation

jaredcwhite
Copy link
Member

This is a 🐛 bug fix.

Summary

Previous versions (3.x) of Webpack'scss-loader wouldn't cause any problems if the file referenced in a stylesheet's url(…) 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 (aka src), rather than pulled from somewhere in Webpack's frontend 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 added file-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 than src, 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

@jaredcwhite jaredcwhite merged commit 36c9210 into main Feb 11, 2021
@jaredcwhite jaredcwhite deleted the fix-css-loader-url-resolve branch February 11, 2021 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs/bug?: Images in src/images can not be referenced in frontend/style.css
1 participant