{"id":20098,"library":"hook-shell-script-webpack-plugin","title":"HookShellScriptWebpackPlugin","description":"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.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/drewloomer/hook-shell-script-webpack-plugin","tags":["javascript","webpack","bash","shell","hook"],"install":[{"cmd":"npm install hook-shell-script-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add hook-shell-script-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add hook-shell-script-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin hooks into webpack compiler lifecycle","package":"webpack","optional":false}],"imports":[{"note":"The package exports via module.exports = class; CommonJS require is correct. ESM import may fail due to lack of named exports.","wrong":"import HookShellScriptPlugin from 'hook-shell-script-webpack-plugin';","symbol":"HookShellScriptPlugin","correct":"const HookShellScriptPlugin = require('hook-shell-script-webpack-plugin');"},{"note":"The class is the default export; destructuring will result in undefined.","wrong":"const { HookShellScriptPlugin } = require('hook-shell-script-webpack-plugin');","symbol":"default","correct":"const HookShellScriptPlugin = require('hook-shell-script-webpack-plugin');"},{"note":"Package has no TypeScript declarations. Consider declaring module manually or using any.","wrong":null,"symbol":"type definitions","correct":"No TypeScript types shipped. Use @types/hook-shell-script-webpack-plugin if available."}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nconst webpack = require('webpack');\nconst HookShellScriptPlugin = require('hook-shell-script-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js'\n  },\n  plugins: [\n    new HookShellScriptPlugin({\n      afterEmit: ['echo \"Build complete!\"'],\n      done: ['echo \"Done!\"']\n    })\n  ]\n};","lang":"javascript","description":"Shows minimal webpack config using plugin to run shell commands after emit and on done."},"warnings":[{"fix":"Use asynchronous hooks or shell backgrounding (&) to avoid blocking.","message":"Commands run synchronously and block the webpack build until completion.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Check Webpack 5 compiler hooks reference and update plugin configuration accordingly.","message":"Hook names like 'afterEmit' are deprecated in Webpack 5; use 'emit' instead.","severity":"deprecated","affected_versions":">=0.3.0"},{"fix":"Use process.env in shell command strings or pass variables via command arguments.","message":"Environment variables from the build are not automatically passed to shell scripts.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider using shell scripts that write to files or use async alternatives like webpack-shell-plugin-next.","message":"The plugin uses child_process.execSync, which may cause issues with large output or long-running scripts.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"If you used array returns for parallel commands, refactor to use object returns for each command.","message":"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.","severity":"breaking","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev hook-shell-script-webpack-plugin and ensure it's in node_modules.","cause":"Plugin not installed or webpack resolve fails.","error":"Module not found: Error: Can't resolve 'hook-shell-script-webpack-plugin'"},{"fix":"Use const HookShellScriptPlugin = require('hook-shell-script-webpack-plugin');","cause":"Using an ES module import statement incorrectly; plugin is a CommonJS default export.","error":"TypeError: HookShellScriptPlugin is not a constructor"},{"fix":"Consult webpack compiler hooks documentation and use the correct hook name for your webpack version.","cause":"Webpack 5 deprecated some hooks; you're using a hook name that no longer exists.","error":"Error: Hook 'afterEmit' is not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}