Webpack-dev-server未检测到文件更改。

3

我有一个使用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()],
};
1个回答

0
你可以尝试将watchFiles属性添加到devServer中。
module.exports = {
    ...
    devServer: {
        watchFiles: [path.resolve(__dirname, '../src/**/*')],
    }
    ...
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接