Problem
I'm trying to create an application with multiple entries, SCSS and automaticly generated HTML pages using the html-webpack plugin. Everyting compiles fine in the dist directory, however when i use the dev server hot reloading is not working. I can see that whenever I make a change the code compiles just fine. I think the problem is caused by the html loader. Is there a fix or work-around to make this work?
webpack.config.js
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
entry: {
test1: "./src/pages/test1.js",
test2: "./src/pages/test2.js"
},
module: {
rules: [
{ test: /\.js$/, exclude: /node_modules/,
use: { loader: "babel-loader" } },
{ test: /\.htm$/,
use: [{loader: "html-loader", options: { minimize: true }}]},
{ test: /\.s?css$/,
use: ["style-loader", "css-loader", "sass-loader"]}]
},
plugins: [
new HtmlWebpackPlugin({filename: "test1.htm",template:
"./src/template.htm", inject: 'true', chunks: ['test1']}),
new HtmlWebpackPlugin({filename: "test2.htm",template:
"./src/template.htm", inject: 'true', chunks: ['test2']}),
new MiniCssExtractPlugin({filename: "[name].css", chunkFilename: "
[id].css"})
]
}
package.json
"scripts": {
"start": "webpack-dev-server --mode development --open",
"build": "webpack --mode production"
}