https://github.com/sysgears/node-hmr-plugin
Webpack plugin for running node process in development mode with HMR
https://github.com/sysgears/node-hmr-plugin
Last synced: 8 months ago
JSON representation
Webpack plugin for running node process in development mode with HMR
- Host: GitHub
- URL: https://github.com/sysgears/node-hmr-plugin
- Owner: sysgears
- License: mit
- Created: 2019-07-30T09:22:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-12T13:25:40.000Z (almost 7 years ago)
- Last Synced: 2025-10-26T01:32:15.248Z (8 months ago)
- Language: JavaScript
- Size: 30 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node HMR Webpack Plugin
[](https://travis-ci.org/sysgears/webpack-virtual-modules)
[](https://twitter.com/sysgears)
**`node-hmr-plugin`** is a Webpack plugin that allows running your Node app during
development in such a way that it doesn't interfere with Webpack Hot Module Replacement.
When you utilize Webpack HMR during Node server app development, the Webpack normally reloads
app code itself. You shouldn't watch for source code changes with external tool like `nodemon`, because Webpack will picks up changes itself and in more efficient way.
However, if your app crashes, it should be re-started after you changed source code and Webpack
compilation finished. The plugin is exactly about supporting this workflow.
# Installation
Use Yarn or NPM to install Node HMR Webpack Plugin as a development dependency:
```bash
# with Yarn
yarn add -D node-hmr-plugin
# with NPM
npm install -D node-hmr-plugin
```
## Configuration
The plugin will do nothing in non-watch mode. In watch mode, the plugin will launch
node application and try to restart it when application crashed and new code changes
were made.
**webpack.config.js**
```js
const NodeHmrPlugin = require('node-hmr-plugin');
module.exports = [
target: 'node',
...
plugins: [
new HotModuleReplacementPlugin(),
new NodeHmrPlugin()
]
};
```
## Plugin options
### cmd *(string) (default='{app}')*
Command template string default: `'{app}'`, it can be for example:
`'--inspect {app} some_arg'`. The `{app}` is replaced with actual path to the compiled bundle.
### restartOnExitCodes *(number[]) (default=none)*
Exit code list that should result in app restart, immediately. It can be used
to handle the edge case when Webpack fails to apply HMR. For example, you can have the code
like this inside your app:
```js
module.hot.status(event => {
if (event === 'abort' || event === 'fail') {
process.exit(250);
}
});
```
and pass `restartOnExitCodes: [250]` option to the plugin to force immediate application
re-start on HMR failure.
### logLevel *(string) (default='info')*
Log level, one of `trace`, `debug`, `info`, `warn`, `error`, `silent`. If you want to silence
plugin, pass `logLevel: 'info'` option.
## License
Copyright © 2019 [SysGears (Cyprus) Limited]. This source code is licensed under the [MIT] license.
[MIT]: LICENSE
[SysGears (Cyprus) Limited]: http://sysgears.com