Event Hooks Webpack Plugin

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

Execute arbitrary JavaScript code on any available Webpack compiler hook. Version 3.0.1 is the latest stable release as of 2025. The plugin provides a simple way to tap into Webpack's compilation lifecycle events (e.g., run, compile, done) by mapping hook names to callback functions. Compared to webpack-shell-plugin, it allows running code (not shell commands) and supports all Tapable hook types via named exports tap, tapAsync, and tapPromise. This package is ESM-only since v3.0.0, requires Node.js with ESM support, Webpack ≥5.82.0, and TypeScript ≥5.5.2. It ships with TypeScript declarations and is released on npm with irregular cadence.

error require() of ES Module /path/to/node_modules/event-hooks-webpack-plugin/index.js from /path/to/webpack.config.js not supported.
cause Using CommonJS require() with ESM-only package.
fix
Convert your webpack config to ESM: use import statements, rename file to .mjs, or add "type": "module" to package.json.
error Cannot find module 'event-hooks-webpack-plugin'
cause Missing or misconfigured peer dependency (TypeScript or Webpack) or package not installed.
fix
Run npm install event-hooks-webpack-plugin webpack@^5.82.0 typescript@^5.5.2 --save-dev
error TypeError: (0 , _eventHooksWebpackPlugin.tapPromise) is not a function
cause Trying to import named exports from v2.x or incorrect import path.
fix
Ensure you are using v3.0.0+ and import correctly: import { tapPromise } from 'event-hooks-webpack-plugin'.
error Error: Hook type not supported: tapAsync for 'initialize' hook
cause Using tapAsync (callback) on a sync-only hook like 'initialize'.
fix
Use tap (sync) for hooks that are not async; check Webpack docs for hook type.
breaking Package is ESM-only since v3.0.0. You must use import statements or a compatible ESM loader.
fix Switch from require() to import statements. Use .mjs extension or configure "type": "module" in package.json.
breaking Exports for Task, CallbackTask, and PromiseTask removed in v3.0.0. They are replaced by tap, tapAsync, and tapPromise.
fix Replace Task with tap, CallbackTask with tapAsync, PromiseTask with tapPromise.
breaking Dropped support for Webpack versions below 5.82.0. Plugin will not work with Webpack 4 or early Webpack 5.
fix Upgrade Webpack to >=5.82.0.
deprecated Version 2.x is deprecated; no longer receiving updates or security fixes.
fix Upgrade to v3.0.0+ and migrate to ESM.
gotcha When using tapPromise, do not call the callback parameter — it is not provided. Only return a Promise.
fix Use tapAsync for callback style hooks; for promise hooks, simply return a Promise.
npm install event-hooks-webpack-plugin
yarn add event-hooks-webpack-plugin
pnpm add event-hooks-webpack-plugin

Shows default export usage and named tap exports (tapPromise, tapAsync) for different hook types in a Webpack config.

import EventHooksPlugin, { tapPromise, tapAsync } from 'event-hooks-webpack-plugin';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  plugins: [
    new EventHooksPlugin({
      compile: () => {
        console.log('Compilation started...');
      },
      emit: tapPromise(async (compilation) => {
        const assets = Object.keys(compilation.assets);
        console.log('Assets being emitted:', assets);
      }),
      done: tapAsync((stats, callback) => {
        console.log('Build completed in', stats.endTime - stats.startTime, 'ms');
        callback();
      }),
    }),
  ],
};