1

I have a build step (a hook) that needs to happen after webpack --watch finishes. Has anyone had success hooking into webpack --watch to determine when it has completed?

In other words it would like this:

  1. start webpack --watch in the background
  2. file(s) change, webpack --watch creates a new build
  3. run some hook after webpack completes the rebuild

does anyone know a good way of doing this?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

1

The simplest way I think will be to use the webpack-shell-plugin plugin. It allows you to run any shell commands before or after webpack builds. Just install it with npm install --save-dev webpack-shell-plugin and edit your webpack.config.js:

const WebpackShellPlugin = require('webpack-shell-plugin');

module.exports = {
  ...
  ...
  plugins: [
    new WebpackShellPlugin({onBuildStart:['echo "Webpack Start"'], onBuildEnd:['echo "Webpack End"']})
  ],
  ...
}

Review plugin docs for a more info.

semanser
  • 2,310
  • 2
  • 15
  • 33
  • thanks, I filed a related issue on the Webpack issue tracker - https://github.com/webpack/webpack/issues/5895, maybe that will give you more context...but I think your answer might work – Alexander Mills Oct 28 '17 at 21:05