{"id":20776,"library":"webpack-hook-plugin","title":"Webpack Hook Plugin","description":"A webpack plugin that runs shell commands at various stages of the webpack build lifecycle: on build start, on build end, on build exit, and on every compile. Version 1.0.7 is the current stable release, with no active development observed since 2023. It supports both webpack and webpack-dev-server, and allows multiple commands per hook. Unlike similar plugins (e.g., webpack-shell-plugin), this one provides a built-in 'dev' switch to avoid repeated execution in watch mode and a 'safe' mode using exec instead of spawn for compatibility.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/tienne/webpack-hook-plugin","tags":["javascript","webpack","shell","plugin","serve","hmr","browser","script","typescript"],"install":[{"cmd":"npm install webpack-hook-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-hook-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-hook-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Has TypeScript types. Default import works with both ESM and CJS. In CJS, use `const WebpackHookPlugin = require('webpack-hook-plugin')` without .default.","wrong":"const WebpackHookPlugin = require('webpack-hook-plugin').default","symbol":"default","correct":"import WebpackHookPlugin from 'webpack-hook-plugin'"},{"note":"Named import is not available; the package exports a single default export.","wrong":"import { WebpackHookPlugin } from 'webpack-hook-plugin'","symbol":"WebpackHookPlugin","correct":"const WebpackHookPlugin = require('webpack-hook-plugin')"},{"note":"TypeScript users can import the type for type annotations.","symbol":"type imports","correct":"import type WebpackHookPlugin from 'webpack-hook-plugin'"}],"quickstart":{"code":"const WebpackHookPlugin = require('webpack-hook-plugin');\n\nmodule.exports = {\n  plugins: [\n    new WebpackHookPlugin({\n      onBuildStart: ['echo \"Webpack Start\"'],\n      onBuildEnd: ['echo \"Webpack End\"'],\n      onBuildExit: ['echo \"Webpack Exit\"'],\n      onCompile: ['echo \"Compile step\"'],\n      dev: false,\n      safe: false\n    })\n  ]\n};","lang":"javascript","description":"Shows full usage with all hooks and options in a webpack config."},"warnings":[{"fix":"Set `dev: false` in the options object.","message":"The `dev` option defaults to true, which causes scripts to execute only once in development mode (webpack-dev-server or watch). If you expect scripts to run on every rebuild, set `dev: false`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set `safe: true` in the options object.","message":"On Windows, the `safe` option may be necessary because `spawn` might not work correctly with shell commands. Setting `safe: true` switches to `exec` which runs in a shell.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `onBuildEnd` instead if you want scripts to run on every rebuild.","message":"The `onBuildExit` hook also fires when webpack --watch finishes updating the bundle, not only when the webpack process exits. This may cause unexpected behavior if you expect it to run only once.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import WebpackHookPlugin from 'webpack-hook-plugin'` or `const WebpackHookPlugin = require('webpack-hook-plugin')`.","cause":"Importing as named export instead of default.","error":"TypeError: WebpackHookPlugin is not a constructor"},{"fix":"Set `safe: true` in the options to use exec instead.","cause":"The `safe` option is false (default), using spawn which may not find the shell on some systems.","error":"Error: spawn ENOENT"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}