forked from webpack-contrib/mini-css-extract-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.js
35 lines (31 loc) · 1023 Bytes
/
hooks.js
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
const { SyncWaterfallHook } = require("tapable");
/** @typedef {import("webpack").Compilation} Compilation */
/**
* @typedef {Object} VarNames
* @property {string} tag
* @property {string} chunkId
* @property {string} href
* @property {string} resolve
* @property {string} reject
*/
/**
* @typedef {Object} MiniCssExtractPluginCompilationHooks
* @property {import("tapable").SyncWaterfallHook<[string, VarNames], string>} beforeTagInsert
*/
/** @type {WeakMap<Compilation, MiniCssExtractPluginCompilationHooks>} */
const compilationHooksMap = new WeakMap();
/**
*
* @param {Compilation} compilation the compilation
* @returns {MiniCssExtractPluginCompilationHooks} the compilation hooks
*/
exports.getCompilationHooks = function getCompilationHooks(compilation) {
let hooks = compilationHooksMap.get(compilation);
if (!hooks) {
hooks = {
beforeTagInsert: new SyncWaterfallHook(["source", "varNames"], "string"),
};
compilationHooksMap.set(compilation, hooks);
}
return hooks;
};