I am currently trying to set up HOT MODULE REPLACEMENT with a my webpack project. At the moment when i make changes to a react component in the source code, I am seeing the module reload in the browser without a refresh, followed by a full refresh of the page.
Here is what I am seeing in the console.
WDS seems to be running TWICE?
- the next line is a 404 when for GET http://localhost:8088/dist/0580e96e5dacd24618e5.hot-update.json 404 (Not Found) i removed this for company privacy :)
then these two lines in the console:
- List item
dev-server.js:28 [HMR] Cannot find update. Need to do a full reload!(anonymous function) @ dev-server.js:28(anonymous function) @
- List item
index.js:238request.onreadystatechange @ index.js:37 dev-server.js:29 [HMR] (Probably because of restarting the webpack-dev-server)
As you can see the 'client:37 [WDS] App updated. Recompiling...' seems to be run TWICE... which is maybe why it is both hot swapping and then doing a full reload.
Any ideas?
Here is my webpack.config
module.exports = {
devtool: 'eval',
cache: true,
entry: {
index: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./js/src/index.js'
],
login: './login/index.js',
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/dist/',
filename: '[name].js',
chunkFilename: '[name].js'
},
module: {
loaders: [
// Transpile ES6 JSX to ES5 JS
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel',
},
// SCSS
{
test: /\.scss$/,
loaders: [
'style',
'css?importLoaders=1&localIdentName=[local]-[hash:base64:5]',
'postcss-loader',
'resolve-url',
'sass'
]
},
{
test: /\.json$/,
loaders: ['json-loader'],
}
]
},
postcss: function () {
return {
defaults: [autoprefixer],
cleaner: [autoprefixer({ browsers: ['last 2 versions'], cascade: true })]
};
},
plugins: [
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en|de|fr|zh|ja|it/),
new webpack.HotModuleReplacementPlugin(),
new webpack.IgnorePlugin(/ReactContext/),
new webpack.DefinePlugin({ 'process.env.apiEndPointUrl': '"'+apiEndPointUrl+'"' }),
new JsonBundlerPlugin({
fileInput: '**/locales/*.json',
omit: /\/locales|\/?components|\/?services|\/?scenes|\/?features/g,
rootDirectory: 'src'
}),
],
resolve: {
extensions: ['', '.js', '.json', '.jsx']
}
};
Here is the devServer.js file i'm running in my npm task.
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const opener = require('opener');
const config = require('./webpack.config.js');
const host = 'localhost';
const port = 8080;
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true // color is life
},
})
.listen(port, host, (err) => {
if (err) {
console.log(err);
}
console.log(`Listening at ${host}:${port}`);
opener(`http://${host}:${port}`);
});