From 7d5b559aec4068c7213f8e0266f7825e3d2becca Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:47:32 +0300 Subject: [PATCH] docs: update (#1841) --- README.md | 2 +- spec/basic.spec.js | 44 ++++++++++++++++++++++---------------------- typings.d.ts | 1 + 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1a062795..d1206dd4 100644 --- a/README.md +++ b/README.md @@ -581,7 +581,7 @@ class MyPlugin { console.log('The compiler is starting a new compilation...') // Static Plugin interface |compilation |HOOK NAME | register listener - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync( + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync( 'MyPlugin', // <-- Set a meaningful name here for stacktraces (data, cb) => { // Manipulate the content diff --git a/spec/basic.spec.js b/spec/basic.spec.js index 43084118..744e546e 100644 --- a/spec/basic.spec.js +++ b/spec/basic.spec.js @@ -1151,7 +1151,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (object, callback) => { expect(Object.keys(object.assetTags)).toEqual(['scripts', 'styles', 'meta']); eventFired = true; callback(); @@ -1185,7 +1185,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { pluginArgs.assetTags.scripts = pluginArgs.assetTags.scripts.map(tag => { if (tag.tagName === 'script') { tag.attributes.specialAttribute = true; @@ -1219,7 +1219,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { pluginArgs.assetTags.scripts = pluginArgs.assetTags.scripts.map(tag => { if (tag.tagName === 'script') { tag.attributes.async = false; @@ -1253,7 +1253,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { pluginArgs.assetTags.scripts = pluginArgs.assetTags.scripts.map(tag => { if (tag.tagName === 'script') { tag.attributes.async = null; @@ -1287,7 +1287,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { pluginArgs.assetTags.scripts = pluginArgs.assetTags.scripts.map(tag => { if (tag.tagName === 'script') { tag.attributes.async = undefined; @@ -1322,7 +1322,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).afterEmit.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).afterEmit.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { eventArgs = pluginArgs; callback(null, pluginArgs); }); @@ -1357,7 +1357,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).afterEmit.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).afterEmit.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => { eventArgs = pluginArgs; callback(null, pluginArgs); }); @@ -1390,7 +1390,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).afterTemplateExecution.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).afterTemplateExecution.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFired = true; callback(); }); @@ -1424,7 +1424,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFired = true; callback(); }); @@ -1457,7 +1457,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).afterEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).afterEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFired = true; callback(); }); @@ -1488,7 +1488,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFired = true; object.html += 'Injected by plugin'; callback(); @@ -1523,7 +1523,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - hookNames = Object.keys(HtmlWebpackPlugin.getHooks(compilation)).sort(); + hookNames = Object.keys(HtmlWebpackPlugin.getCompilationHooks(compilation)).sort(); }); } }; @@ -1561,7 +1561,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFiredForFirstPlugin = true; object.html += 'Injected by first plugin'; callback(null, object); @@ -1572,7 +1572,7 @@ describe('HtmlWebpackPlugin', () => { const secondExamplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFiredForSecondPlugin = true; object.html += ' Injected by second plugin'; callback(null); @@ -1610,7 +1610,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFiredForFirstPlugin = true; const result = _.extend(object, { html: object.html + 'Injected by first plugin' @@ -1623,7 +1623,7 @@ describe('HtmlWebpackPlugin', () => { const secondExamplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFiredForSecondPlugin = true; object.html += ' Injected by second plugin'; callback(null); @@ -1661,7 +1661,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFiredForFirstPlugin = true; const result = _.extend(object, { html: object.html + 'Injected by first plugin' @@ -1674,7 +1674,7 @@ describe('HtmlWebpackPlugin', () => { const secondExamplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFiredForSecondPlugin = true; const result = _.extend(object, { html: object.html + ' Injected by second plugin' @@ -1711,7 +1711,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).afterTemplateExecution.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).afterTemplateExecution.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFired = true; object.bodyTags.push(HtmlWebpackPlugin.createHtmlTagObject('script', { src: 'funky-script.js' })); object.html += 'Injected by plugin'; @@ -1747,7 +1747,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeAssetTagGeneration.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFired = true; object.assets.js.push('funky-script.js'); callback(); @@ -1782,7 +1782,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync('HtmlWebpackPluginTest', (object, callback) => { + HtmlWebpackPlugin.getCompilationHooks(compilation).beforeAssetTagGeneration.tapAsync('HtmlWebpackPluginTest', (object, callback) => { eventFired = true; object.assets.js.push('funky-script.js'); callback(); @@ -1823,7 +1823,7 @@ describe('HtmlWebpackPlugin', () => { const examplePlugin = { apply: function (compiler) { compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => { - const hooks = HtmlWebpackPlugin.getHooks(compilation); + const hooks = HtmlWebpackPlugin.getCompilationHooks(compilation); hookLength = hooks.length; // Hook into all hooks Object.keys(hooks).forEach((hookName) => { diff --git a/typings.d.ts b/typings.d.ts index 451a2bfd..5de022b5 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -20,6 +20,7 @@ declare class HtmlWebpackPlugin { apply(compiler: Compiler): void; static getHooks(compilation: Compilation): HtmlWebpackPlugin.Hooks; + static getCompilationHooks(compilation: Compilation): HtmlWebpackPlugin.Hooks; /** * Static helper to create a tag object to be get injected into the dom