webpack-dev-middleware for node targets. It starts a webpack watcher, runs an output file, and sends signals for it to refresh whenever new code is generated.
To hot-reload both the server and the client during development of universal applications.
-
npm install --save-dev webpack-dev-node -
Add
webpack/hot/signalas an entry -
Add
HotModuleReplacementPluginandNoErrorsPluginas plugins
{
target: 'node',
entry: [
'webpack/hot/signal',
],
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
}
-
Add
module.hot.accepthooks as you see fit. Refer to webpack HMR documentation for instructions. Usedynamic-middlewareto easily replace connect middleware. -
Finally, run
webpack-dev-node
or
webpack-dev-node --config webpack.config.js --chunk main