Skip to content

Commit

Permalink
docs: update (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Feb 5, 2024
1 parent b548944 commit 7d5b559
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions spec/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
}
};
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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'
Expand All @@ -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);
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d5b559

Please sign in to comment.