Here is my server code:
if (process.env.NODE_ENV === 'development') {
// Enable logger (morgan)
app.use(morgan('dev'));
// Disable views cache
app.set('view cache', false);
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var webpackConfig = require('../client/webpack.config');
var compiler = webpack(webpackConfig);
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }));
app.use(webpackHotMiddleware(compiler));
}
and here is my webpack.config:
module.exports = {
entry: {
main: [
'webpack-hot-middleware/client',
'./client/src/main'
]
},
output: {
path: path.join(__dirname, 'client/build'),
filename: 'bundle.js',
publicPath: '/build/'
},
plugins: [
new AureliaWebpackPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{ test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: {stage: 0} },
{ test: /\.css?$/, loader: 'style!css' },
{ test: /\.html$/, loader: 'raw' },
{ test: /\.(png|gif|jpg)$/, loader: 'url-loader?limit=8192' },
{ test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff2' },
{ test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' }
]
}
};
Every time I change a source file, webpack rebuilds no problem. However, there is no hot replacement/reload in the browser...Am I missing something? I thought I followed the instructions pretty closely.
Thanks in advance.
My issue was successfully resolved when I added some parameters to webpack-hot-middleware to enable HMR, and query parameters to webpack-hot-middleware/client in entry, like so:
//#server.js add parameters to Enables HMR
app
.use(webpackHotMiddleware(compiler, {
'log': false,
'path': '/__webpack_hmr',
'heartbeat': 10 * 1000
}))
//# webpack.config.js:
entry: {
main: [
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true',
'./client/src/main'
]
So my issue was actually covered in the docs. I was using the compression module upstream of webpack-hot-middleware and hadn't updated compression.
See this issue: https://github.com/glenjamin/webpack-hot-middleware/issues/10
Basically, if you are using compression make sure you upgrade to ^1.6. I upgraded 1.2 -> 1.6.1 and it I am getting hot reloading now.
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