webpack-dev-server热重载器无法正常工作

时间:2019-11-03 23:41:51

标签: webpack webpack-dev-server

尝试运行webpack-dev-server时,热重载器没有反映我正在编写的任何更改,而是必须停止webpack-dev-server并先运行yarn build:dev然后再运行{{1 }}。我需要对我的yarn start配置进行哪些更改,以确保热加载器正常工作?您可以找到实际的仓库here

package.json:

devServer

webpack.dev.js:

{
  ...
  "scripts": {
    ...
    "start": "webpack-dev-server --config webpack.dev.js",
    "build:dev": "npm-run-all remove-dist devWebpack copy-index",
    ...
  },
  ...
}

webpack.common.js:

const merge = require('webpack-merge');
const common = require('./webpack.common.js');

const config = merge(common, {
  mode: 'development',
  devtool: 'inline-source-map',
  devServer: {
    contentBase: './dist',
    historyApiFallback: true,
    hot: true,
    allowedHosts: [
      'localhost',
    ],
  },
});

module.exports = config;

1 个答案:

答案 0 :(得分:1)

See here来解决问题。谢谢。