I am using HTMLWebpackPlugin and in my template I have an img tag:
<img src="./images/logo/png">
If you notice, here I am using a relative path thinking webpack will trigger the file loader that's configured in my webpack.config.js file but after compilation I get the exact same src attribute in my html:
<img src="./images/logo/png">
How can I trigger webpack to dynamically replace these relative paths with, well whatever I've configured in my webpack configuration?
You could use url-loader in your webpack config to add images below a certain limit encoded as base64 uri's in your final bundle and images above the limit as regular image tags (relative to the publicPath)
Using html-loader with HTML webpack plugin worked for me.
I'm not a webpack expert, but i got it to work by doing this
Plugin config
According to the docs: https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
The
<%= %>
signifies a lodash templateCalling
require
on your img path will then call the file loader.You may run into some path issues, but it should work.
You should use the
CopyWebpackPlugin
.const CopyWebpackPlugin = require('copy-webpack-plugin');
This is copy the
src/assets/images
to your `distfolder/images'.