@@ -845,9 +845,10 @@ class MiniCssExtractPlugin {
845
845
const { chunkGraph, chunk, runtimeRequirements } = this ;
846
846
const {
847
847
runtimeTemplate,
848
- outputOptions : { crossOriginLoading } ,
848
+ outputOptions : { chunkLoadingGlobal , crossOriginLoading } ,
849
849
} = this . compilation ;
850
850
const chunkMap = getCssChunkObject ( chunk , this . compilation ) ;
851
+ const globalObject = runtimeTemplate . globalObject ;
851
852
const { linkPreload, linkPrefetch } =
852
853
JsonpChunkLoadingRuntimeModule . getCompilationHooks ( compilation ) ;
853
854
const conditionMap = chunkGraph . getChunkConditionMap (
@@ -868,6 +869,9 @@ class MiniCssExtractPlugin {
868
869
const withPreload = runtimeRequirements . has (
869
870
RuntimeGlobals . preloadChunkHandlers
870
871
) ;
872
+ const chunkLoadingGlobalExpr = `${ globalObject } [${ JSON . stringify (
873
+ chunkLoadingGlobal
874
+ ) } ]`;
871
875
872
876
if ( ! withLoading && ! withHmr ) {
873
877
return "" ;
@@ -993,6 +997,23 @@ class MiniCssExtractPlugin {
993
997
) ,
994
998
"};" ,
995
999
"" ,
1000
+ `var webpackJsonpCallback = ${ runtimeTemplate . basicFunction (
1001
+ "parentChunkLoadingFunction, data" ,
1002
+ [
1003
+ runtimeTemplate . destructureArray ( [ "chunkIds" ] , "data" ) ,
1004
+ "for(var i=0;i < chunkIds.length; i++) {" ,
1005
+ Template . indent ( [
1006
+ "var chunkId = chunkIds[i];" ,
1007
+ "installedCssChunks[chunkId] = 0;" ,
1008
+ ] ) ,
1009
+ "}" ,
1010
+ ]
1011
+ ) } `,
1012
+ "" ,
1013
+ `var chunkLoadingGlobal = ${ chunkLoadingGlobalExpr } = ${ chunkLoadingGlobalExpr } || [];` ,
1014
+ "chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));" ,
1015
+ "chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));" ,
1016
+ "" ,
996
1017
`${
997
1018
RuntimeGlobals . ensureChunkHandlers
998
1019
} .miniCss = ${ runtimeTemplate . basicFunction (
@@ -1213,6 +1234,12 @@ class MiniCssExtractPlugin {
1213
1234
compilation . hooks . runtimeRequirementInTree
1214
1235
. for ( RuntimeGlobals . hmrDownloadUpdateHandlers )
1215
1236
. tap ( pluginName , handler ) ;
1237
+ compilation . hooks . runtimeRequirementInTree
1238
+ . for ( RuntimeGlobals . prefetchChunkHandlers )
1239
+ . tap ( pluginName , handler ) ;
1240
+ compilation . hooks . runtimeRequirementInTree
1241
+ . for ( RuntimeGlobals . preloadChunkHandlers )
1242
+ . tap ( pluginName , handler ) ;
1216
1243
} ) ;
1217
1244
}
1218
1245
0 commit comments