@@ -848,7 +848,7 @@ class MiniCssExtractPlugin {
848
848
outputOptions : { crossOriginLoading } ,
849
849
} = this . compilation ;
850
850
const chunkMap = getCssChunkObject ( chunk , this . compilation ) ;
851
- const { linkPrefetch } =
851
+ const { linkPreload , linkPrefetch } =
852
852
JsonpChunkLoadingRuntimeModule . getCompilationHooks ( compilation ) ;
853
853
const conditionMap = chunkGraph . getChunkConditionMap (
854
854
chunk ,
@@ -865,6 +865,9 @@ class MiniCssExtractPlugin {
865
865
const withPrefetch = runtimeRequirements . has (
866
866
RuntimeGlobals . prefetchChunkHandlers
867
867
) ;
868
+ const withPreload = runtimeRequirements . has (
869
+ RuntimeGlobals . preloadChunkHandlers
870
+ ) ;
868
871
869
872
if ( ! withLoading && ! withHmr ) {
870
873
return "" ;
@@ -1104,6 +1107,51 @@ class MiniCssExtractPlugin {
1104
1107
"}" ,
1105
1108
] ) } ;`
1106
1109
: "// no prefetching" ,
1110
+ "" ,
1111
+ withPreload && hasCssMatcher !== false
1112
+ ? `${
1113
+ RuntimeGlobals . preloadChunkHandlers
1114
+ } .miniCss = ${ runtimeTemplate . basicFunction ( "chunkId" , [
1115
+ `if((!${
1116
+ RuntimeGlobals . hasOwnProperty
1117
+ } (installedCssChunks, chunkId) || installedCssChunks[chunkId] === undefined) && ${
1118
+ hasCssMatcher === true ? "true" : hasCssMatcher ( "chunkId" )
1119
+ } ) {`,
1120
+ Template . indent ( [
1121
+ "installedCssChunks[chunkId] = null;" ,
1122
+ linkPreload . call (
1123
+ Template . asString ( [
1124
+ "var link = document.createElement('link');" ,
1125
+ "link.charset = 'utf-8';" ,
1126
+ `if (${ RuntimeGlobals . scriptNonce } ) {` ,
1127
+ Template . indent (
1128
+ `link.setAttribute("nonce", ${ RuntimeGlobals . scriptNonce } );`
1129
+ ) ,
1130
+ "}" ,
1131
+ 'link.rel = "preload";' ,
1132
+ 'link.as = "style";' ,
1133
+ `link.href = ${ RuntimeGlobals . publicPath } + ${ RuntimeGlobals . require } .miniCssF(chunkId);` ,
1134
+ crossOriginLoading
1135
+ ? crossOriginLoading === "use-credentials"
1136
+ ? 'link.crossOrigin = "use-credentials";'
1137
+ : Template . asString ( [
1138
+ "if (link.href.indexOf(window.location.origin + '/') !== 0) {" ,
1139
+ Template . indent (
1140
+ `link.crossOrigin = ${ JSON . stringify (
1141
+ crossOriginLoading
1142
+ ) } ;`
1143
+ ) ,
1144
+ "}" ,
1145
+ ] )
1146
+ : "" ,
1147
+ ] ) ,
1148
+ chunk
1149
+ ) ,
1150
+ "document.head.appendChild(link);" ,
1151
+ ] ) ,
1152
+ "}" ,
1153
+ ] ) } ;`
1154
+ : "// no preloaded" ,
1107
1155
] ) ;
1108
1156
}
1109
1157
}
0 commit comments