So I've migrated my Rails application over to Webpack but I'm having trouble loading image assets. In the Webpacker documentation it states that I can load my assets using the following:
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
But this doesn't seem to be compiled down when I run rails webpacker:compile
My folder structure looks like so
app/javascript:
├── packs:
│ # only webpack entry files here
│ └── application.js
└── src:
│ └── application.css
└── images:
└── logo.svg
and my webpacker.yml
contains:
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
I'm not great at this new Webpack stuff but I assume it has something to do with my webpacker.yml
Has anyone experienced this before? There seems to be little advice on the internet.
Ta!
I think I can resolve this by manually importing the images from inside my application.js
So for example;
# /app/javascript/packs/application.js
import '../images/logo.svg';
Then lets me reference this using the asset_pack_path
Still if somebody can tell me a better way i'd really appreciate it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.