I am able to get the src attribute correct when importing images in my js files. But not when specifying img src url in my html code. How to get the correct url in html automatically whenver i build the project.
webpack.config
module.exports = {
entry: {
"main-page": "./src/scripts/index.js",
},
output: {
filename: "bundle.[name].[contenthash].js",
path: path.resolve(__dirname, "./dist"),
publicPath: "static/",
},
module: {
rules: [
{
test: /\.(png|jpg)$/,
use: ["file-loader"],
},
{
test: /\.hbs$/,
use: ["handlebars-loader"],
},
]
},
plugins: [
new HTMLWebpackPlugin({
template: "src/handlebars/index.hbs",
filename: "index.html",
}),
],
}
somefile.js
import Image from "../assests/img.jpg";
const imgEle=document.createElement("img");
imgEle.src=Image; // gets corrrectly refrenced to md5hash.jpg in the bundle
index.hbs (using handlebars)
<img src="?" /> // what to do here so that it correctly gets refrenced.