HookShellScriptWebpackPlugin

raw JSON →
0.4.0 verified Sat Apr 25 auth: no javascript

A Webpack plugin (v0.4.0) that executes arbitrary shell scripts in response to Webpack compiler hooks. It integrates with the full range of Webpack compiler hooks (afterEmit, done, assetEmitted, etc.). Supports running single commands, multiple parallel commands, and dynamic command generation from hook arguments via functions. Uses instead of exec for robust process handling. Compatible with Webpack 4 and 5. Released under MIT; maintained by Drew Loomer. Key differentiator: simple, functional approach compared to alternatives like webpack-shell-plugin.

error Module not found: Error: Can't resolve 'hook-shell-script-webpack-plugin'
cause Plugin not installed or webpack resolve fails.
fix
Run npm install --save-dev hook-shell-script-webpack-plugin and ensure it's in node_modules.
error TypeError: HookShellScriptPlugin is not a constructor
cause Using an ES module import statement incorrectly; plugin is a CommonJS default export.
fix
Use const HookShellScriptPlugin = require('hook-shell-script-webpack-plugin');
error Error: Hook 'afterEmit' is not supported
cause Webpack 5 deprecated some hooks; you're using a hook name that no longer exists.
fix
Consult webpack compiler hooks documentation and use the correct hook name for your webpack version.
gotcha Commands run synchronously and block the webpack build until completion.
fix Use asynchronous hooks or shell backgrounding (&) to avoid blocking.
deprecated Hook names like 'afterEmit' are deprecated in Webpack 5; use 'emit' instead.
fix Check Webpack 5 compiler hooks reference and update plugin configuration accordingly.
gotcha Environment variables from the build are not automatically passed to shell scripts.
fix Use process.env in shell command strings or pass variables via command arguments.
gotcha The plugin uses child_process.execSync, which may cause issues with large output or long-running scripts.
fix Consider using shell scripts that write to files or use async alternatives like webpack-shell-plugin-next.
breaking From v0.4.0, hook functions must return either a string or an object with command and args; returning an array is no longer supported.
fix If you used array returns for parallel commands, refactor to use object returns for each command.
npm install hook-shell-script-webpack-plugin
yarn add hook-shell-script-webpack-plugin
pnpm add hook-shell-script-webpack-plugin

Shows minimal webpack config using plugin to run shell commands after emit and on done.

// webpack.config.js
const path = require('path');
const webpack = require('webpack');
const HookShellScriptPlugin = require('hook-shell-script-webpack-plugin');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  plugins: [
    new HookShellScriptPlugin({
      afterEmit: ['echo "Build complete!"'],
      done: ['echo "Done!"']
    })
  ]
};