-
Notifications
You must be signed in to change notification settings - Fork 1.5k
webpacker 4.0.0.rc2: images are not accessible from rails views #1839
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
@deepj What happens if you put your images under packs folder? |
@gauravtiwari Unfortunately, without luck. But the manifesto looks now (the location of image is
|
What happens if you do this? Is this an image?
|
@gauravtiwari Hm, it works. It generates the following path <img src="/packs/packs/images/test-7a25cb51be37d1334cf2274ba9194279.jpg" /> There is no Here is my current file structure: |
Can confirm, |
What happens if you do this in // top of packs/application.js
const importAll = (r) => r.keys().map(r)
importAll(require.context('../images', false, /\.(png|jpe?g|svg)$/)); This will load all images from images folder and then it should be available in manifest for you to pick up using |
The images folder should be outside |
With importAll it works. |
Great, thanks @grk Like mentioned in the README, everything must go through packs (entrypoint) for it to be available in the end. If you want a bunch of images to be available in the view, best to use We don't recommend putting anything other than |
@gauravtiwari It works with I believe, Importing them via " I wish there would be some option in These are my thoughts about this topic |
I believe that's relates to #1887 @gauravtiwari has made a fix, but document has a tiny bug need to be fixed. For my experience, |
If you do this, you can remove sprockets, because Webpacker take care all frontend resources, but if you don't know Rails too much, I recommends you keep sprockets, and don't place resources which handled by Webpacker into |
@jasl thanks, but you don't fully understand my issues. No, I don't use sprockets at all. I recommend you re-read this issue. If some changes have been made since this issue was reported, then it's good. |
hey @deepj, Does it work for you if your images are in a subfolder like so :
Because it does not work for me, even with the @gauravtiwari's It only works for images at the root of My importAll method : const importAll = (r) => r.keys().map(r)
importAll(require.context('../images', true, /\.(png|jpe?g|svg)$/)) EDIT: I only tried on 4.0.0.rc7 EDIT 2 : I figured out why it does not work. It does import the images even in subfolders but with a wrong path in the manifest. It's because of the rc6 changes https://github.com/rails/webpacker/blob/master/CHANGELOG.md#400rc6---2019-01-25 The path are now |
Inside the js file: |
For me, the solution was to add this line After that, I was able to use the |
Yes, We can close this issue. |
Hello,
I've made a fresh webpacker 4.0.0.rc2 installation and I'm trying to load an image from assets in a rails view
The image is located in multiple paths (
app/assets/images/test.jpg
,app/javascript/images/test.jpg
))I don't see the file would be in the manifest
I though, webpacker 4.0.0rc2 has out-of-box solution for this simple use case. I won't really import the image in
application.js
. I'd like to use it in the same way as using sprocket.The text was updated successfully, but these errors were encountered: