Webpack热重载不更新reducer

时间:2017-06-22 12:06:22

标签: javascript webpack webpack-dev-middleware webpack-hot-middleware

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

我的网络包配置:

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等。我认为它不会改变任何东西。 当我更新我的一个Reducer时,我仍然会收到以下错误。

  

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

user.js中需要

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

0 个答案:

没有答案