-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Webpack v4 rc7 images wrong pack reference #1915
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
Comments
Hi, @JanStevens Earlier, we had full path embedded relative to the context for static assets, however, to simplify this I changed it just file name and hash. That media folder is just a namespace for static assets so you would need it before calling any static file through webpacker. And calling images are much simpler now, no nested sub-directories - "media/google.jpg": "/packs/media/google-97e897b3.jpg",
"media/rails.png": "/packs/media/rails-45b116b1.png", You would notice, everything is now under the correct directory, inside packs folder for simplicity instead of dumping everything in the packs folder. |
Here is bit more background on the earlier issue: https://github.com/rails/webpacker/blob/master/CHANGELOG.md#fixed-1 |
Hello, Yea I found that link (stupid should first check the Changelog ofcourse), I'm just a bit concerned that flatting it out would cause some naming issues if I have two files name exactly the same but in a sub directory, example:
This would result in one company.png image instead of two (and the logo is a smaller one for example) |
Yes of course, I know. I guess that was the reason for earlier change and adding context option in the first place but it seemed it caused more harm especially, for assets inside I guess a simple fix for this would be to name images correctly instead of directory namespacing - Obviously, if you don't want the behaviour you can update file loader to include context option but it seems not having is much better generally, const { environment, config } = require('@rails/webpacker')
const { join } = require('path')
const fileLoader = environment.loaders.get('file')
fileLoader.use[0].options.context = join(config.source_path) |
Sorry, this came as bit of surprise but we all learn :) |
Oke that makes it clear, I think some added documentation in the README might be handy as also a guide on how to add images in your pack with webpack. Thanks for the fast reply! |
Sure, documentation needs overhauling a bit. If you have some time, please make a PR and I will merge. |
Hi, Is there a way to make it work like the old way? The above mentioned solution doesn't work for me. Our whole app is namespaced (like frontend/app1/images, frontend/app2/images, frontend/app3/images) and each app had it's own entrypoint with but with the new update nothing works anymore, which needs a refactor of the entire image import system with hundreds of image references... any solution? |
Any error you getting? const { environment, config } = require('@rails/webpacker')
const { join } = require('path')
const fileLoader = environment.loaders.get('file')
fileLoader.use[0].options.context = join(config.source_path) https://github.com/webpack-contrib/file-loader#context (need to set this variable to app source) |
Well I am probably doing something wrong because I assumed I could just paste that code in environment.js but many variables are undefined and webpack 'cannot find @rails/webpacker/config'. I'm not that familiar with advanced webpack configs, could you maybe give a more extended example? |
Updated the example, just wrote off the top of my head. My bad :) |
Hello,
We are following every RC update so today I upgraded from rc5 to rc7 and I noticed that all my images now need to be references differently. To get started some configuration files:
In our main
application.js
file we require the images (else they would never be included in the pack)Our
environment.js
didn't change, we do add the sassresolve-url-loader
For example the favicon in RC5 could be referenced as:
But in RC7 this needs to be
Even more problematic are subdirectories in the images (for example
app/javascript/images/logo/brand-color.png
), in RC5In RC7 this got changed again to media but it also removed the subdir
So I'm wondering how I should reference images correctly and if that subdirectory is not a bug or something.
Regards
The text was updated successfully, but these errors were encountered: