@@ -15,6 +15,7 @@ const {
1515 getUndoPath,
1616 BASE_URI ,
1717} = require ( "./utils" ) ;
18+ const { getHooks } = require ( "./hooks" ) ;
1819
1920/** @typedef {import("schema-utils/declarations/validate").Schema } Schema */
2021/** @typedef {import("webpack").Compiler } Compiler */
@@ -511,6 +512,14 @@ class MiniCssExtractPlugin {
511512 return CssDependency ;
512513 }
513514
515+ /**
516+ * Returns all hooks for the given compiler
517+ * @param {Compiler } compiler
518+ */
519+ static getHooks ( compiler ) {
520+ return getHooks ( compiler ) ;
521+ }
522+
514523 /**
515524 * @param {PluginOptions } [options]
516525 */
@@ -838,7 +847,6 @@ class MiniCssExtractPlugin {
838847 if ( ! withLoading && ! withHmr ) {
839848 return "" ;
840849 }
841-
842850 return Template . asString ( [
843851 'if (typeof document === "undefined") return;' ,
844852 `var createStylesheet = ${ runtimeTemplate . basicFunction (
@@ -895,6 +903,12 @@ class MiniCssExtractPlugin {
895903 "}" ,
896904 ] )
897905 : "" ,
906+ MiniCssExtractPlugin . getHooks ( compiler ) . beforeTagInsert ?. call ( {
907+ varNames : {
908+ chunkId : "chunkId" ,
909+ tag : "linkTag" ,
910+ } ,
911+ } ) ,
898912 typeof this . runtimeOptions . insert !== "undefined"
899913 ? typeof this . runtimeOptions . insert === "function"
900914 ? `(${ this . runtimeOptions . insert . toString ( ) } )(linkTag)`
@@ -912,7 +926,7 @@ class MiniCssExtractPlugin {
912926 "}" ,
913927 ] ) ,
914928 "return linkTag;" ,
915- ]
929+ ] . filter ( ( statement ) => statement !== undefined )
916930 ) } ;`,
917931 `var findStylesheet = ${ runtimeTemplate . basicFunction (
918932 "href, fullhref" ,
0 commit comments