2

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"
  }

1 Answer 1

0

Im super new to configuring webpack so im not sure if this is correct or will help but here is my start script in my package.json and my hot reload works fine:

"scripts": {
 "start:dev": "webpack-dev-server --mode development --config config/webpack.base.config.js --open --hot --history-api-fallback",

so from my understanding using "--hot" is what tells webpack to enable the hot reloading.

i used this resource to help me configure webpack. Its pretty basic but it might help. https://medium.freecodecamp.org/how-to-conquer-webpack-4-and-build-a-sweet-react-app-236d721e6745

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.