33const path = require ( "path" ) ;
44
55const { validate } = require ( "schema-utils" ) ;
6+ const { SyncWaterfallHook } = require ( "tapable" ) ;
67
78const schema = require ( "./plugin-options.json" ) ;
89const {
@@ -15,7 +16,6 @@ const {
1516 getUndoPath,
1617 BASE_URI ,
1718} = require ( "./utils" ) ;
18- const { getCompilationHooks } = require ( "./hooks" ) ;
1919
2020/** @typedef {import("schema-utils/declarations/validate").Schema } Schema */
2121/** @typedef {import("webpack").Compiler } Compiler */
@@ -89,16 +89,23 @@ const CODE_GENERATION_RESULT = {
8989} ;
9090
9191/** @typedef {Module & { content: Buffer, media?: string, sourceMap?: Buffer, supports?: string, layer?: string, assets?: { [key: string]: TODO }, assetsInfo?: Map<string, AssetInfo> } } CssModule */
92-
9392/** @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-
9593/** @typedef {{ new(dependency: CssModuleDependency): CssModule } } CssModuleConstructor */
96-
9794/** @typedef {Dependency & CssModuleDependency } CssDependency */
98-
9995/** @typedef {Omit<LoaderDependency, "context"> } CssDependencyOptions */
100-
10196/** @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+ */
102109
103110/**
104111 *
@@ -114,6 +121,9 @@ const cssDependencyCache = new WeakMap();
114121 */
115122const registered = new WeakSet ( ) ;
116123
124+ /** @type {WeakMap<Compilation, MiniCssExtractPluginCompilationHooks> } */
125+ const compilationHooksMap = new WeakMap ( ) ;
126+
117127class MiniCssExtractPlugin {
118128 /**
119129 * @param {Compiler["webpack"] } webpack
@@ -519,7 +529,19 @@ class MiniCssExtractPlugin {
519529 * @param {Compilation } compilation
520530 */
521531 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 ;
523545 }
524546
525547 /**
0 commit comments