Alexander Mills
Alexander Mills

Reputation: 100010

Library tooling - hooking into `webpack --watch`

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?

Upvotes: 1

Views: 464

Answers (1)

semanser
semanser

Reputation: 2348

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.

Upvotes: 1

Related Questions