33 Author Tobias Koppers @sokra
44*/
55"use strict" ;
6+
7+ const sortByIndex = ( a , b ) => {
8+ return a . index - b . index ;
9+ } ;
10+
11+ const sortByIndex2 = ( a , b ) => {
12+ return a . index2 - b . index2 ;
13+ } ;
14+
615class ChunkModuleIdRangePlugin {
716 constructor ( options ) {
817 this . options = options ;
918 }
19+
1020 apply ( compiler ) {
1121 const options = this . options ;
1222 compiler . hooks . compilation . tap ( "ChunkModuleIdRangePlugin" , compilation => {
1323 compilation . hooks . moduleIds . tap ( "ChunkModuleIdRangePlugin" , modules => {
14- const chunk = this . chunks . find ( chunk => chunk . name === options . name ) ;
15- if ( ! chunk )
24+ const chunk = compilation . chunks . find (
25+ chunk => chunk . name === options . name
26+ ) ;
27+ if ( ! chunk ) {
1628 throw new Error (
17- " ChunkModuleIdRangePlugin: Chunk with name '" +
18- options . name +
19- "' was not found"
29+ ` ChunkModuleIdRangePlugin: Chunk with name '${
30+ options . name
31+ } "' was not found`
2032 ) ;
21- let currentId = options . start ;
33+ }
34+
2235 let chunkModules ;
2336 if ( options . order ) {
24- chunkModules = chunk . modules . slice ( ) ;
37+ chunkModules = Array . from ( chunk . modulesIterable ) ;
2538 switch ( options . order ) {
2639 case "index" :
27- chunkModules . sort ( ( a , b ) => {
28- return a . index - b . index ;
29- } ) ;
40+ chunkModules . sort ( sortByIndex ) ;
3041 break ;
3142 case "index2" :
32- chunkModules . sort ( ( a , b ) => {
33- return a . index2 - b . index2 ;
34- } ) ;
43+ chunkModules . sort ( sortByIndex2 ) ;
3544 break ;
3645 default :
3746 throw new Error (
@@ -40,10 +49,11 @@ class ChunkModuleIdRangePlugin {
4049 }
4150 } else {
4251 chunkModules = modules . filter ( m => {
43- return m . chunks . includes ( chunk ) ;
52+ return m . chunksIterable . has ( chunk ) ;
4453 } ) ;
4554 }
4655
56+ let currentId = options . start || 0 ;
4757 for ( let i = 0 ; i < chunkModules . length ; i ++ ) {
4858 const m = chunkModules [ i ] ;
4959 if ( m . id === null ) {
0 commit comments