@@ -222,21 +222,14 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
222
222
var id = this . id ;
223
223
var extractedChunks , entryChunks , initialChunks ;
224
224
compilation . plugin ( "optimize-tree" , function ( chunks , modules , callback ) {
225
- extractedChunks = chunks . map ( function ( ) {
226
- return new Chunk ( ) ;
225
+ extractedChunks = chunks . map ( function ( chunk ) {
226
+ return new Chunk ( chunk . name ) ;
227
227
} ) ;
228
228
chunks . forEach ( function ( chunk , i ) {
229
229
var extractedChunk = extractedChunks [ i ] ;
230
- extractedChunk . index = i ;
231
- extractedChunk . originalChunk = chunk ;
232
230
extractedChunk . name = chunk . name ;
233
- extractedChunk . entrypoints = chunk . entrypoints ;
234
- chunk . chunks . forEach ( function ( c ) {
235
- extractedChunk . addChunk ( extractedChunks [ chunks . indexOf ( c ) ] ) ;
236
- } ) ;
237
- chunk . parents . forEach ( function ( c ) {
238
- extractedChunk . addParent ( extractedChunks [ chunks . indexOf ( c ) ] ) ;
239
- } ) ;
231
+ extractedChunk . originalChunk = chunk ;
232
+ splitChunk ( chunk , extractedChunk ) ;
240
233
} ) ;
241
234
async . forEach ( chunks , function ( chunk , callback ) {
242
235
var extractedChunk = extractedChunks [ chunks . indexOf ( chunk ) ] ;
@@ -355,32 +348,53 @@ function isChunk(chunk, error) {
355
348
function forEachChunkModule ( chunk , cb ) {
356
349
isChunk ( chunk ) ;
357
350
351
+ // webpack >= 4.x.x
352
+ if ( chunk . modulesIterable ) {
353
+ Array . from ( chunk . modulesIterable , ( x ) => {
354
+ cb ( x ) ;
355
+ return x ;
356
+ } )
357
+ }
358
358
// webpack >= 3.x.x
359
- if ( typeof chunk . forEachModule === 'function' ) {
359
+ else if ( typeof chunk . forEachModule === 'function' ) {
360
360
chunk . forEachModule ( cb ) ;
361
361
}
362
+ // webpack < 3.x.x
362
363
else {
363
- // webpack < 3.x.x
364
364
chunk . modules . forEach ( cb ) ;
365
365
}
366
-
367
- // Nothing better to return...
368
- return chunk ;
369
366
}
370
367
371
368
function getChunkModulesArray ( chunk ) {
372
369
isChunk ( chunk ) ;
373
370
374
- var arr = [ ] ;
375
-
371
+ // webpack >= 4.x.x
372
+ if ( chunk . modulesIterable ) {
373
+ return Array . from ( chunk . modulesIterable ) ;
374
+ }
376
375
// webpack >= 3.x.x
377
- if ( typeof chunk . mapModules === 'function' ) {
378
- arr = chunk . mapModules ( ) ;
376
+ else if ( typeof chunk . mapModules === 'function' ) {
377
+ return chunk . mapModules ( ) ;
379
378
}
380
379
else {
381
380
// webpack < 3.x.x
382
- arr = chunk . modules . slice ( ) ;
381
+ return chunk . modules . slice ( ) ;
383
382
}
383
+ }
384
384
385
- return arr ;
385
+ function splitChunk ( chunk , extractedChunk ) {
386
+ // webpack >= 4.x.x
387
+ if ( typeof chunk . split === 'function' ) {
388
+ chunk . split ( extractedChunk ) ;
389
+ }
390
+ // webpack < 4.x.x
391
+ else {
392
+ extractedChunk . entrypoints = chunk . entrypoints ;
393
+ chunk . chunks . forEach ( function ( c ) {
394
+ extractedChunk . addChunk ( extractedChunks [ chunks . indexOf ( c ) ] ) ;
395
+ } ) ;
396
+ chunk . parents . forEach ( function ( c ) {
397
+ extractedChunk . addParent ( extractedChunks [ chunks . indexOf ( c ) ] ) ;
398
+ } ) ;
399
+ }
386
400
}
0 commit comments