diff --git a/index.js b/index.js index 7ce48402..b436bee0 100644 --- a/index.js +++ b/index.js @@ -30,10 +30,8 @@ const { AsyncSeriesWaterfallHook } = require("tapable"); /** @typedef {Array<{ name: string, source: import('webpack').sources.Source, info?: import('webpack').AssetInfo }>} PreviousEmittedAssets */ /** @typedef {{ publicPath: string, js: Array, css: Array, manifest?: string, favicon?: string }} AssetsInformationByGroups */ /** @typedef {import("./typings").Hooks} HtmlWebpackPluginHooks */ -/** - * @type {WeakMap}} - */ -const compilationHooksMap = new WeakMap(); + +const compilationHooksSymbol = Symbol.for('html-webpack-plugin/compilation-hooks'); class HtmlWebpackPlugin { // The following is the API definition for all available hooks @@ -98,7 +96,7 @@ class HtmlWebpackPlugin { * @returns {HtmlWebpackPluginHooks} */ static getCompilationHooks(compilation) { - let hooks = compilationHooksMap.get(compilation); + let hooks = compilation[compilationHooksSymbol]; if (!hooks) { hooks = { @@ -109,7 +107,9 @@ class HtmlWebpackPlugin { beforeEmit: new AsyncSeriesWaterfallHook(["pluginArgs"]), afterEmit: new AsyncSeriesWaterfallHook(["pluginArgs"]), }; - compilationHooksMap.set(compilation, hooks); + Object.defineProperty(compilation, compilationHooksSymbol, { + value: hooks, + }) } return hooks;