我有一个使用webpack和babel设置的react应用程序。我正在尝试启用webpack的hmr,它似乎工作良好,但当我更改/src/目录下的任何文件时,它不重新编译。更改package.json确实被检测到并强制重新编译,但即使在重新编译后,/src/目录下的更改仍然未被检测到。我的webpack.config如下:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
main: './src/index.js',
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: 'bundle.js',
},
devServer: {
hot: true,
contentBase: './public/',
publicPath: '/',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: path.join(__dirname),
use: ['babel-loader'],
},
],
},
plugins: [new webpack.HotModuleReplacementPlugin()],
};