/nodemon-webpack-plugin

A webpack plugin that uses Nodemon to start and reload the server.

Primary LanguageJavaScriptMIT LicenseMIT

Nodemon Webpack Plugin

Build Status NPM Version Node version

Uses Nodemon to watch and restart your module's output file, but only when webpack is in watch mode (ie, --watch).

Saves the need for installing, configuring and running Nodemon as a seperate process.

Installation

npm install nodemon-webpack-plugin --save-dev

Usage

const NodemonPlugin = require( 'nodemon-webpack-plugin' ) // Ding

module.exports = {
    entry: './src/server.js',
    output: {
        path: path.resolve('./dist'),
        filename: 'server.js',
    },
    plugins: [
        new NodemonPlugin(), // Dong
    ],
}

Then:

$ webpack --watch

Modes

Zero-config mode

new NodemonPlugin()

Only watches the output file.

With config

Allows a Nodemon config object to override and extend the default config:

{
    script: outputFile,
    watch:  outputFile,
}

For example:

new NodemonPlugin({
    /// Arguments to pass to the script being watched.
    args: ['demo'],

    // What to watch.
    watch: path.resolve('./dist'),

    // Files to ignore.
    ignore: ['*.js.map'],

    // Detailed log.
    verbose: true,

    // Node arguments.
    nodeArgs: [ '--debug=9222' ],

    // If using more than one entry, you can specify
    // which output file will be restarted.
    script: './dist/server.js',

    // Extensions to watch
    ext: 'js,njk,json'
})

Example output

Hash: 366cbbbab13237b29593
Version: webpack 3.4.1
Time: 50ms
    Asset     Size  Chunks             Chunk Names
server.js  3.17 kB       0  [emitted]  main
   [0] ./test/server.js 388 bytes {0} [built]
    + 3 hidden modules
[nodemon] restarting due to changes...
[nodemon] starting `node test/dist/server.js`