Webpack dev服务器没有监听React项目中的更改

时间:2018-06-11 04:42:01

标签: webpack webpack-dev-server

我正在开发一个React项目,我在其中配置了Web包。

在localhost,我正在运行webpack-dev-server,它工作正常。

自从过去几天开始,当我执行Ctrl + c时,我开始收到以下消息。

还有一个问题,即如果在项目中进行了任何更改,则此开发服务器不会自动重新加载服务器和浏览器。

vishal@vishal-pc:~/Desktop/web-app$ node[12104]: ../src/node.cc:4012:void node::PlatformExit(): Assertion `(err) != (-1)' failed.
 1: node::Abort() [node]
 2: 0x893875 [node]
 3: 0x897872 [node]
 4: 0x7f8ad503cff8 [/lib/x86_64-linux-gnu/libc.so.6]
 5: 0x7f8ad503d045 [/lib/x86_64-linux-gnu/libc.so.6]
 6: 0x893a94 [node]
 7: 0xb00af9 [node]
 8: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 9: 0x3b50720041bd

对于每一次更改,我都需要停止开发服务器并再次运行它。

Webpack.config

const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpack = require('webpack');

module.exports = (env) => {
    const isProduction = env === 'production';
    const CSSExtract = new ExtractTextPlugin('styles.css');

    return {
        entry: ['babel-polyfill','./src/app.js'],
        output: {
            path : path.join(__dirname, 'public', 'dist'),
            filename: 'bundle.js'
        },
        module: {
            rules: [
                {
                    loader: 'babel-loader',
                    test: /\.js$/,
                    exclude: /node_modules/
                },
                {
                    test: /\.css$/,
                    use: CSSExtract.extract({
                        fallback: 'style-loader',
                        use: [
                            {
                                loader: 'css-loader',
                                options: {
                                    sourceMap: true
                                }
                            }
                        ]
                    })
                },
                {
                    test: /\.(png|jp(e*)g|gif|svg)$/,
                    use: [
                        {
                            loader: 'url-loader',
                            options: {
                                limit: 8000,
                                name: 'images/[hash]-[name].[ext]',
                                publicPath: '/dist/'
                            }
                        }
                    ]
                },
                {
                    test: /\.(woff|woff2|eot|ttf|otf|mp4)$/,
                    use: [
                        {
                            loader: "file-loader",
                            options: {
                                name: 'files/[hash]-[name].[ext]',
                                publicPath: '/dist/'
                            }
                        }
                    ]

                }
            ]
        },
        plugins: [
            CSSExtract,
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                "window.jQuery": "jquery"
            })
        ],
        devtool: isProduction ? 'source-map' : 'cheap-module-eval-source-map',
        devServer: {
            contentBase: path.join(__dirname, 'public'),
            historyApiFallback: true,
            publicPath: '/dist/'
        }
    }
}

1 个答案:

答案 0 :(得分:0)

对我来说,升级到10.5很有帮助。我的猜测是这个问题:https://github.com/nodejs/node/issues/20297