What?
If you need to reload only part of your app whithout restarting whole process when code require
d from this part was changed, then hot-module-reload
fit your needs.
Install
$ npm install hot-module-reload --save
How to use?
Pass function to hot-module-reload
, it will run it synchronously and then re-run it every time code require
d from this function is changed.
var HotReload = require('hot-module-reload');
var devServer = { close:() => {} };
HotReload(() => {
var config = require('./webpack.client.config');
devServer.close();
devServer = new webpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
proxy: {
'*': 'http://localhost:' + port
}
});
devServer.listen(devPort, () => {
debug('dev server started on port ' + devPort);
});
});
var appServer = { close:(cb) => { cb(); } };
HotReload(() => {
var app = require('./server/app');
appServer.close(() => {
appServer = app.listen(port, () => {
debug('app server started on port ' + port);
});
})
});
In this example dev server and app server will be reloaded separately, and process will not crash if updated code doesn't compile.
License
MIT