@@ -131,6 +131,25 @@ class MiniCssExtractPlugin {
131
131
}
132
132
} ) ;
133
133
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
+ ) ;
134
153
mainTemplate . hooks . requireEnsure . tap (
135
154
'mini-css-extract-plugin' ,
136
155
( source , chunk , hash ) => {
@@ -164,9 +183,10 @@ class MiniCssExtractPlugin {
164
183
'' ,
165
184
'// mini-css-extract-plugin CSS loading' ,
166
185
`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]) {' ,
168
188
Template . indent ( [
169
- 'promises.push(new Promise(function(resolve, reject) {' ,
189
+ 'promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {' ,
170
190
Template . indent ( [
171
191
'var linkTag = document.createElement("link");' ,
172
192
'linkTag.rel = "stylesheet";' ,
@@ -175,6 +195,7 @@ class MiniCssExtractPlugin {
175
195
`linkTag.href = ${ mainTemplate . requireFn } .p + ${ linkHrefPath } ;` ,
176
196
'var head = document.getElementsByTagName("head")[0];' ,
177
197
'head.appendChild(linkTag);' ,
198
+ 'installedCssChunks[chunkId] = 0;' ,
178
199
] ) ,
179
200
'}));' ,
180
201
] ) ,
0 commit comments