Webpack Shell Plugin
raw JSON → 0.5.0 verified Sat Apr 25 auth: no javascript maintenance
A webpack plugin that executes shell commands before and after webpack builds. Version 0.5.0 requires webpack 4+ (peer dependency). It supports arrays of commands for start, end, and exit phases, and provides a 'dev' mode to avoid re-running scripts in watch/watch-dev-server. Unlike alternatives like shelljs-webpack-plugin, it uses spawn by default but offers a 'safe' flag to fall back to exec. The plugin is unmaintained since 2019 and may have issues with webpack 5.
Common errors
error Error: Cannot find module 'webpack-shell-plugin' ↓
cause Module not installed or incorrect import path.
fix
Run 'npm install --save-dev webpack-shell-plugin' and use require('webpack-shell-plugin') in webpack.config.js.
Warnings
deprecated The 'verbose' option is deprecated and has no effect. ↓
fix Remove the verbose option from the plugin configuration.
gotcha On Windows, spawn may fail due to shell differences. Use the 'safe' option to switch to exec which uses cmd. ↓
fix Add { safe: true } to options.
gotcha The plugin does not expose a return value for scripts; any errors may not be caught. ↓
fix Wrap scripts in try-catch or redirect stderr to a log.
breaking Plugin may not work with webpack 5 without modification due to removed legacy plugin API. ↓
fix Use a fork like 'webpack-shell-plugin-next' or upgrade to a maintained plugin.
Install
npm install webpack-shell-plugin yarn add webpack-shell-plugin pnpm add webpack-shell-plugin Imports
- WebpackShellPlugin wrong
import WebpackShellPlugin from 'webpack-shell-plugin';correctconst WebpackShellPlugin = require('webpack-shell-plugin');
Quickstart
const WebpackShellPlugin = require('webpack-shell-plugin');
const path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src/app.js'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
plugins: [
new WebpackShellPlugin({
onBuildStart: ['echo "Build started"'],
onBuildEnd: ['echo "Build ended"'],
onBuildExit: ['echo "Webpack process complete"'],
dev: false
})
]
};