3
3
const path = require ( "path" ) ;
4
4
5
5
const { validate } = require ( "schema-utils" ) ;
6
+ const { SyncWaterfallHook } = require ( "tapable" ) ;
6
7
7
8
const schema = require ( "./plugin-options.json" ) ;
8
9
const {
@@ -15,7 +16,6 @@ const {
15
16
getUndoPath,
16
17
BASE_URI ,
17
18
} = require ( "./utils" ) ;
18
- const { getCompilationHooks } = require ( "./hooks" ) ;
19
19
20
20
/** @typedef {import("schema-utils/declarations/validate").Schema } Schema */
21
21
/** @typedef {import("webpack").Compiler } Compiler */
@@ -89,16 +89,23 @@ const CODE_GENERATION_RESULT = {
89
89
} ;
90
90
91
91
/** @typedef {Module & { content: Buffer, media?: string, sourceMap?: Buffer, supports?: string, layer?: string, assets?: { [key: string]: TODO }, assetsInfo?: Map<string, AssetInfo> } } CssModule */
92
-
93
92
/** @typedef {{ context: string | null, identifier: string, identifierIndex: number, content: Buffer, sourceMap?: Buffer, media?: string, supports?: string, layer?: TODO, assetsInfo?: Map<string, AssetInfo>, assets?: { [key: string]: TODO }} } CssModuleDependency */
94
-
95
93
/** @typedef {{ new(dependency: CssModuleDependency): CssModule } } CssModuleConstructor */
96
-
97
94
/** @typedef {Dependency & CssModuleDependency } CssDependency */
98
-
99
95
/** @typedef {Omit<LoaderDependency, "context"> } CssDependencyOptions */
100
-
101
96
/** @typedef {{ new(loaderDependency: CssDependencyOptions, context: string | null, identifierIndex: number): CssDependency } } CssDependencyConstructor */
97
+ /**
98
+ * @typedef {Object } VarNames
99
+ * @property {string } tag
100
+ * @property {string } chunkId
101
+ * @property {string } href
102
+ * @property {string } resolve
103
+ * @property {string } reject
104
+ */
105
+ /**
106
+ * @typedef {Object } MiniCssExtractPluginCompilationHooks
107
+ * @property {import("tapable").SyncWaterfallHook<[string, VarNames], string> } beforeTagInsert
108
+ */
102
109
103
110
/**
104
111
*
@@ -114,6 +121,9 @@ const cssDependencyCache = new WeakMap();
114
121
*/
115
122
const registered = new WeakSet ( ) ;
116
123
124
+ /** @type {WeakMap<Compilation, MiniCssExtractPluginCompilationHooks> } */
125
+ const compilationHooksMap = new WeakMap ( ) ;
126
+
117
127
class MiniCssExtractPlugin {
118
128
/**
119
129
* @param {Compiler["webpack"] } webpack
@@ -519,7 +529,19 @@ class MiniCssExtractPlugin {
519
529
* @param {Compilation } compilation
520
530
*/
521
531
static getCompilationHooks ( compilation ) {
522
- return getCompilationHooks ( compilation ) ;
532
+ let hooks = compilationHooksMap . get ( compilation ) ;
533
+
534
+ if ( ! hooks ) {
535
+ hooks = {
536
+ beforeTagInsert : new SyncWaterfallHook (
537
+ [ "source" , "varNames" ] ,
538
+ "string"
539
+ ) ,
540
+ } ;
541
+ compilationHooksMap . set ( compilation , hooks ) ;
542
+ }
543
+
544
+ return hooks ;
523
545
}
524
546
525
547
/**
0 commit comments