1

我正在为 express 运行 webpack-hot-reload 和 webpack-dev-server 中间件。

我的 webpack 配置:

const webpackConfig = {
    entry: [
        project.app.entry,
    ],
    output: {
        path: project.path.out,
        filename: 'bundle.js',
        publicPath: '/',
    },
    module: {
            rules: [],
    },
    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify(process.env.NODE_ENV),
            },
        }),
    ],
    devtool: DEV ? 'source-map' : false,
};

我的 index.js

import React from 'react';
import ReactDom from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';

import App from './containers/App';
import store from './store';

const MOUNT_NODE = document.getElementById('root');

function render() {
    ReactDom.render(
        <Provider store={store}>
            <Router>
                <App />
            </Router>
        </Provider>
    , MOUNT_NODE);
}

if (process.env.NODE_ENV === 'development' && module.hot) {
    module.hot.accept('./containers/App', () => render());
    module.hot.accept('./reducers/index.js', () => {
        console.log('Accepted');
        store.replaceReducer(require('./reducers').default);
        render();
    });
}

render();

Webpack 稍后添加了更多配置:eslint、babel-loader 等。我认为它不会改变任何东西。当我更新我的一个减速器时,我仍然收到以下错误。

以下模块无法热更新:(需要完全重新加载)./client/reducers/user.js

user.js但是当我在reducer/index.js App.js 文件中重新加载组件时它工作正常,该文件也是热重新加载的。我该如何解决这个问题?

4

0 回答 0