为什么使用 webpack-dev-server 时 __webpack_hmr 路由是 404?

问题描述

我有以下 webpack 配置并使用 webpack-dev-server --hot 启动我的开发服务器。但是 hmr 似乎不起作用。在浏览器控制台中,我看到 GET http://localhost:8080/__webpack_hmr 404 (Not Found)

已经花了几个小时浏览文档和各种文章。似乎我在这里遗漏了一些重要的东西。

使用 webpack 4.46.0、webpack-dev-server 3.11.2 和 webpack-cli 3.3.12。

const path = require('path')
const { isDev,rules,plugins,resolve } = require('./webpack.shared')

const contentBase = path.resolve(__dirname,'public')
const publicPath = '.webpack'

module.exports = {
  mode: isDev ? 'development' : 'production',devtool: isDev ? 'eval-source-map' : undefined,entry: path.resolve(__dirname,'src','browser','renderer.tsx'),output: {
    path: path.resolve(contentBase,publicPath),filename: 'bundle.js',},module: {
    rules,resolve,devServer: {
    contentBase,publicPath: '/' + publicPath,hot: true,proxy: {
      '/api': {
        target: 'https://api.example.com',pathRewrite: { '^/api': '' },secure: false,changeOrigin: true,'/lp': {
        target: 'https://lp.example.com',pathRewrite: { '^/lp': '' },}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)