-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhooks.js
More file actions
107 lines (100 loc) · 2.98 KB
/
hooks.js
File metadata and controls
107 lines (100 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// @ts-check
'use strict';
/**
* This file provides access to all public htmlWebpackPlugin hooks
*/
/** @typedef {import("webpack").Compilation} WebpackCompilation */
/** @typedef {import("./index.js")} HtmlRspackPlugin */
/** @typedef {import("../typings").Hooks} HtmlRspackPluginHooks */
const { AsyncSeriesWaterfallHook } = require('@rspack/lite-tapable');
// The following is the API definition for all available hooks
// For the TypeScript definition, see the Hooks type in typings.d.ts
/**
beforeAssetTagGeneration:
AsyncSeriesWaterfallHook<{
assets: {
publicPath: string,
js: Array<string>,
css: Array<string>,
favicon?: string | undefined
},
outputName: string,
plugin: HtmlRspackPlugin
}>,
alterAssetTags:
AsyncSeriesWaterfallHook<{
assetTags: {
scripts: Array<HtmlTagObject>,
styles: Array<HtmlTagObject>,
meta: Array<HtmlTagObject>,
},
publicPath: string,
outputName: string,
plugin: HtmlRspackPlugin
}>,
alterAssetTagGroups:
AsyncSeriesWaterfallHook<{
headTags: Array<HtmlTagObject | HtmlTagObject>,
bodyTags: Array<HtmlTagObject | HtmlTagObject>,
publicPath: string,
outputName: string,
plugin: HtmlRspackPlugin
}>,
afterTemplateExecution:
AsyncSeriesWaterfallHook<{
html: string,
headTags: Array<HtmlTagObject | HtmlTagObject>,
bodyTags: Array<HtmlTagObject | HtmlTagObject>,
outputName: string,
plugin: HtmlRspackPlugin,
}>,
beforeEmit:
AsyncSeriesWaterfallHook<{
html: string,
outputName: string,
plugin: HtmlRspackPlugin,
}>,
afterEmit:
AsyncSeriesWaterfallHook<{
outputName: string,
plugin: HtmlRspackPlugin
}>
*/
/**
* @type {WeakMap<WebpackCompilation, HtmlRspackPluginHooks>}}
*/
const htmlWebpackPluginHooksMap = new WeakMap();
/**
* Returns all public hooks of the html webpack plugin for the given compilation
*
* @param {WebpackCompilation} compilation
* @returns {HtmlRspackPluginHooks}
*/
function getHtmlRspackPluginHooks(compilation) {
let hooks = htmlWebpackPluginHooksMap.get(compilation);
// Setup the hooks only once
if (hooks === undefined) {
hooks = createHtmlRspackPluginHooks();
htmlWebpackPluginHooksMap.set(compilation, hooks);
}
return hooks;
}
/**
* Add hooks to the webpack compilation object to allow foreign plugins to
* extend the HtmlRspackPlugin
*
* @returns {HtmlRspackPluginHooks}
*/
function createHtmlRspackPluginHooks() {
return {
beforeAssetTagGeneration: new AsyncSeriesWaterfallHook(['pluginArgs']),
alterAssetTags: new AsyncSeriesWaterfallHook(['pluginArgs']),
alterAssetTagGroups: new AsyncSeriesWaterfallHook(['pluginArgs']),
afterTemplateExecution: new AsyncSeriesWaterfallHook(['pluginArgs']),
beforeEmit: new AsyncSeriesWaterfallHook(['pluginArgs']),
afterEmit: new AsyncSeriesWaterfallHook(['pluginArgs']),
};
}
module.exports = {
getHtmlRspackPluginHooks,
};