{"id":27545,"library":"webpack-plugin-compat","title":"webpack plugin compat","description":"A compatibility layer for the webpack plugin API that simplifies supporting both v4 and pre-v4 versions (v3/v2). Current version 1.0.4 adds support for Tapable v2.0. Key differentiators: transparent event name mapping (spaces/hyphens to camelCase), HookMap support via space-delimited tokens, special-cased parser events, and a unified reg/tap API that works across webpack versions. Maintained by the Dojo toolkit team.","status":"active","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/chuckdumont/webpack-plugin-compat","tags":["javascript","webpack","plugin","tapable","compatibility"],"install":[{"cmd":"npm install webpack-plugin-compat","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-plugin-compat","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-plugin-compat","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export; requires destructuring from package.","wrong":"const Tapable = require('webpack-plugin-compat')","symbol":"Tapable","correct":"import { Tapable } from 'webpack-plugin-compat'"},{"note":"reg is a top-level export; do not chain .for() on import.","wrong":"const { reg } = require('webpack-plugin-compat').for('myPlugin')","symbol":"reg","correct":"import { reg } from 'webpack-plugin-compat'"},{"note":"tap is available only via the 'for' submodule. Import from 'webpack-plugin-compat/for' or use tap.for() after import.","wrong":"import { tap } from 'webpack-plugin-compat';","symbol":"tap","correct":"import { tap } from 'webpack-plugin-compat/for';\nconst tapNamed = tap.for('myPlugin');"}],"quickstart":{"code":"import { Tapable, reg } from 'webpack-plugin-compat';\nimport { tap } from 'webpack-plugin-compat/for';\n\n// Create a plugin instance (Tapable is dummy in webpack v4, real in v3)\nconst plugin = new Tapable();\n\n// Register a hook (noop in webpack v3)\nreg(plugin, 'myHook', ['Sync', 'arg1', 'arg2']);\n\n// Tap into the hook (requires a plugin name via .for)\nconst tapWithName = tap.for('myPlugin');\ntapWithName(plugin, 'myHook', (arg1, arg2) => {\n  console.log(arg1, arg2);\n});\n\n// Trigger the hook\nplugin.hooks.myHook.call('hello', 'world');","lang":"typescript","description":"Demonstrates basic usage: creating a Tapable plugin object, registering a SyncHook, tapping it with a named plugin, and calling the hook."},"warnings":[{"fix":"Use `import { tap } from 'webpack-plugin-compat/for'` or `const { tap } = require('webpack-plugin-compat/for');`","message":"The `tap` function is NOT available as a top-level export; you must import from 'webpack-plugin-compat/for' or use `.for('name')` after importing the main module.","severity":"gotcha","affected_versions":"*"},{"fix":"Use camelCase event names explicitly to avoid ambiguity, or use HookMap tokens for space-delimited names.","message":"Event names are automatically camelCased for webpack v4+. For example, 'my-event' becomes 'myEvent'. This may cause unexpected collisions or mismatches if you rely on exact naming.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your code is compatible with Tapable v2 (e.g., no direct access to Tapable internals).","message":"In v1.0.4, support for Tapable v2.0 was added. Plugins relying on Tapable v1 internals may break.","severity":"breaking","affected_versions":">=1.0.4"},{"fix":"Upgrade to webpack 5+ and remove this dependency.","message":"Pre-v4 webpack (v2, v3) are no longer actively maintained. Using this package for new development is discouraged; migrate to webpack 5+.","severity":"deprecated","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import { tap } from 'webpack-plugin-compat/for'` and then `tap.for('myPlugin')`.","cause":"Trying to use `tap` directly from the main import without going through `.for()` or the 'for' submodule.","error":"TypeError: Cannot read properties of undefined (reading 'tap')"},{"fix":"Ensure the HookMap is registered via `reg(plugin, 'evaluateTypeof', ...)` or remove spaces from the event name.","cause":"The event name includes spaces intended for HookMap matching, but no matching HookMap exists on the plugin object.","error":"Error: HookMap not found for 'evaluate typeof require'"},{"fix":"Ensure your package manager resolves the package correctly. Try using a direct import: `const { tap } = require('webpack-plugin-compat').for('name');`","cause":"The submodule path 'webpack-plugin-compat/for' is not resolved correctly, possibly due to symlinks or missing package exports.","error":"Module not found: Can't resolve 'webpack-plugin-compat/for'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}