@@ -131,6 +131,25 @@ class MiniCssExtractPlugin {
131131 }
132132 } ) ;
133133 const { mainTemplate } = compilation ;
134+ mainTemplate . hooks . localVars . tap (
135+ 'mini-css-extract-plugin' ,
136+ ( source , chunk ) => {
137+ const chunkMap = this . getCssChunkObject ( chunk ) ;
138+ if ( Object . keys ( chunkMap ) . length > 0 ) {
139+ return Template . asString ( [
140+ source ,
141+ '' ,
142+ '// object to store loaded CSS chunks' ,
143+ 'var installedCssChunks = {' ,
144+ Template . indent (
145+ chunk . ids . map ( id => `${ JSON . stringify ( id ) } : 0` ) . join ( ',\n' ) ,
146+ ) ,
147+ '}' ,
148+ ] ) ;
149+ }
150+ return source ;
151+ } ,
152+ ) ;
134153 mainTemplate . hooks . requireEnsure . tap (
135154 'mini-css-extract-plugin' ,
136155 ( source , chunk , hash ) => {
@@ -164,9 +183,10 @@ class MiniCssExtractPlugin {
164183 '' ,
165184 '// mini-css-extract-plugin CSS loading' ,
166185 `var cssChunks = ${ JSON . stringify ( chunkMap ) } ;` ,
167- 'if(cssChunks[chunkId]) {' ,
186+ 'if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);' ,
187+ 'else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {' ,
168188 Template . indent ( [
169- 'promises.push(new Promise(function(resolve, reject) {' ,
189+ 'promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {' ,
170190 Template . indent ( [
171191 'var linkTag = document.createElement("link");' ,
172192 'linkTag.rel = "stylesheet";' ,
@@ -175,6 +195,7 @@ class MiniCssExtractPlugin {
175195 `linkTag.href = ${ mainTemplate . requireFn } .p + ${ linkHrefPath } ;` ,
176196 'var head = document.getElementsByTagName("head")[0];' ,
177197 'head.appendChild(linkTag);' ,
198+ 'installedCssChunks[chunkId] = 0;' ,
178199 ] ) ,
179200 '}));' ,
180201 ] ) ,
0 commit comments