尝试运行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;