简体   繁体   中英

React hot reload not working with webpack 4

React hot reload is not working. In webpack entry, I have following code.

entry: {
        home: [
            'webpack-dev-server/client?http://0.0.0.0:8000', 
            'webpack/hot/dev-server', // add "only-dev-server" prevents reload on syntax errors
            path.join(__dirname, 'app/home-styles.js')
        ],
        main: [
            'babel-polyfill',
            path.join(__dirname, 'app/styles.js'),
            path.join(__dirname, 'app/vendor.js'),
            path.join(__dirname, 'app/index.js')
        ]
    },

and in dev-server I have hot = true;

and i have below code for wrapping Provider in hot

class Root extends Component {
    render() {
        const { store, history } = this.props;
        return (
            <Provider store={store}>
                <Router history={history} routes={routes(store)}/>
            </Provider>
        );
    }
}

export default hot(module)(Root);

This is result in console, but nothing happens when there is some change. So basically it appears as if hot reload is working but.. no changes reflects. What am I missing here. ? 在此输入图像描述

I am using react 16.2.* and react-hot-loader @4.0.* an webpack @4.5.*

try updating your dev server config like so

const devServerOptions = {
    contentBase: './dist',
    hot: true,
    host: 'beta.whenidev.net',
    https: true,
  };
// if you're adding a dev server entry do it like this
  WebpackDevServer.addDevServerEntrypoints(config, devServerOptions);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM