0.4.1 • Published 10 years ago

hot-module-reload v0.4.1

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

What?

If you need to reload only part of your app whithout restarting whole process when code required 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 required 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