How does one remove all references of HMR when bundling for production?
My production Webpack config has no references to HMR and yet in the browser debugger the client is constantly making a xhr call to /__webpack_hmr
Can anyone shed a light on this?
-- my config
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
path.resolve(__dirname, 'master/jsx/App')
],
output: {
path: path.resolve(__dirname, 'build'),
publicPath: '/dist/',
filename: 'app.bundle.js'
},
cache: false,
devtool: 'sourcemap',
resolve: {
extensions: ['', '.js', '.jsx']
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
})
],
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/
}, {
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react'],
compact: false
}
}, {
test: /\.css$/,
loader: "style-loader!css-loader"
}, {
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
loader: 'url?prefix=font/&limit=10000'
}]
}
};
Hot Module Replacement (HMR) exchanges, adds, or removes modules while an application is running, without a full reload. This can significantly speed up development in a few ways: Retain application state which is lost during a full reload. Save valuable development time by only updating what's changed.
You can use the CLI to modify the webpack-dev-server configuration with the following command: webpack serve --hot-only . Now let's update the index. js file so that when a change inside print. js is detected we tell webpack to accept the updated module.
webpack configThis will let Webpack inject a websocket into the page so that it can notify the browser when it is time to do a Hot Reload.
Hot Module Replacement (HMR) is the ability to push file updates to the browser without triggering a full page refresh. Imagine changing some CSS, hitting save, and then instantly seeing your change reflected on the page without a refresh. That's HMR.
Depends on how you setup your config. I have a node environment variable that tells me if i'm running in production mode or not. If it isn't production, I setup webpackDevMiddleware with the following in my server.js.
if (process.env.NODE_ENV !== 'production') {
app.use(connectLiveReload());
let config = require('./webpack.config'),
compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(webpackHotMiddleware(compiler));
}
In addition, you might want to control the middleware client on the front end from firing calls:
entry: [
'webpack-hot-middleware/client',
'./src/index'
]
by controlling that input using process.env.NODE_ENV !== 'production'
in the webpack.config.js.
Refer to running webpack in production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With