Installed the latest react-hot-loader
yarn add react-hot-loader@next
Updated the entry point:
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/app.jsx'
],
Added react-hot-loader/babel to babel plugins:
{
test: /.jsx?$/,
loader: 'babel-loader',
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
options: {
presets: [['es2015', { modules: false }], 'react'],
plugins: ['react-hot-loader/babel']
}
},
Added the HMR plugin
plugins: [
new CopyWebpackPlugin([
{ from: 'src/index.html' }
]),
new WriteFilePlugin(),
new webpack.HotModuleReplacementPlugin()
],
Used AppContainer
import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import Home from './components/home';
const render = Component => {
ReactDOM.render(
<AppContainer>
<Home />
</AppContainer>,
document.getElementById('react')
)
};
render(Home);
if (module.hot) {
module.hot.accept('./components/home', () => render(Home));
}
And still does not work. The page does a full reload.
Ok, Figured out this one after an hour of googling and reading. With Webpack 2 and above, the following configuration should be added to devServer:
In the earlier Webpack documentation which I referred to, it suggested this: