webpack-event-plugin
raw JSON → 1.1.1 verified Sat Apr 25 auth: no javascript
A webpack plugin that executes callbacks after specified compiler hooks (e.g., afterEmit, done). Version 1.1.1 is the latest stable release; no frequent updates. It is similar to on-build-webpack but allows multiple hooks with per-hook callbacks. Useful for running post-build tasks like asset deployment or notification. Limited to webpack 4+ compiler hooks; no tapable integration for async hooks.
Common errors
error TypeError: compiler.hooks[this.hook] is not a function ↓
cause Hook name is not a valid webpack compiler hook or is misspelled.
fix
Use only hook names from webpack compiler hooks (e.g., 'done', 'afterEmit').
error Error: Hook is not defined ↓
cause Hook name does not exist on compiler.hooks.
fix
Check webpack version: compiler hooks changed between versions. Use compatible hook names.
error TypeError: WebpackEventPlugin is not a constructor ↓
cause Trying to import ES module style with import or misspelling the plugin name.
fix
Use require('webpack-event-plugin') and ensure correct spelling.
Warnings
gotcha Constructor expects an array of hook config objects, not a single object. ↓
fix Wrap single config in an array: new WebpackEventPlugin([{...}])
gotcha Plugin does not support async hooks or promises; callbacks run synchronously. ↓
fix Use webpack's built-in compiler hooks directly for async behavior.
gotcha Hook names must match webpack compiler hooks exactly (e.g., 'afterEmit', 'done'). ↓
fix Refer to webpack compiler hooks documentation for correct names.
Install
npm install webpack-event-plugin yarn add webpack-event-plugin pnpm add webpack-event-plugin Imports
- WebpackEventPlugin wrong
import WebpackEventPlugin from 'webpack-event-plugin'correctconst WebpackEventPlugin = require('webpack-event-plugin') - WebpackEventPlugin wrong
new WebpackEventPlugin({ hook: 'done', callback: () => {} })correctnew WebpackEventPlugin([{ hook: 'done', callback: () => {} }]) - WebpackEventPlugin wrong
// applied to compiler after compile compiler.hooks.done.tap('Plugin', new WebpackEventPlugin(...))correct// in webpack config plugins array plugins: [new WebpackEventPlugin(...)]
Quickstart
const WebpackEventPlugin = require('webpack-event-plugin');
module.exports = {
// ... other webpack config
plugins: [
new WebpackEventPlugin([
{
hook: 'afterEmit',
callback: (compilation) => {
console.log('Build complete! Assets emitted.');
}
},
{
hook: 'done',
callback: (stats) => {
console.log(`Build finished in ${stats.endTime - stats.startTime}ms`);
}
}
])
]
};