Webpack hot update is invalid

1. Project structure:

clipboard.png

2.webpack.config.jspackage.json:

clipboard.png

3.index.html:

clipboard.png

question:
1. The console information shows that the hot update should be successful, but the page has not been refreshed, and the dist file has not changed. How to modify the configuration?
what is the relationship between 2.webpack-dev-server and HotModuleReplacePlugin,webpack-dev-middlevare webpack-hot-middle?


if your webpack4 or react project can consider using this for hot updates react-hot-loader , just report one layer in the router location, for example, export default hot (module) (AppRouter) ,

your method requires an additional line of code in entry. According to my own erection, I need ['webpack-dev-server/client', _ dirname + "/ src/main.js],

.

or execute this method in the entry file

if(module.hot)
     {
         module.hot.accept();
     }

my configuration:
package.json

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "watch": "webpack --watch",
    "start": "webpack-dev-server --open",
    "build": "webpack --env.production"
  }

webapck.config.js

  devServer: {
        host: '0.0.0.0',
        useLocalIp: true,
        contentBase: path.resolve(__dirname, 'dist'),
        openPage: "webpack-dev-server",
        compress: true,
        port: 9000,
        open: true,
    }

did you find the problem? I encountered this, too.


my dev-server configuration

const hotMiddleware = require('webpack-hot-middleware')(compiler, {
  log: false,
  heartbeat: 2000
})
app.use(hotMiddleware)

dev-client configuration

'use strict'
require('eventsource-polyfill')
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')

hotClient.subscribe(function (event) {
  if (event.action === 'reload') {
    window.location.reload()
  }
})
Menu