@@ -8,7 +8,7 @@ let path = require("path");
88
99function makeRelative ( context ) {
1010 return function ( module ) {
11- let identifier = module . identifier ( ) ;
11+ const identifier = module . identifier ( ) ;
1212 return identifier . split ( "|" ) . map ( ( str ) => {
1313 return str . split ( "!" ) . map ( ( str ) => {
1414 return path . relative ( context , str ) ;
@@ -42,7 +42,7 @@ function isNotAEntryModule(entryModule) {
4242}
4343
4444function copyWithReason ( obj ) {
45- let newObj = { } ;
45+ const newObj = { } ;
4646 Object . keys ( obj ) . forEach ( ( key ) => {
4747 newObj [ key ] = obj [ key ] ;
4848 } ) ;
@@ -62,18 +62,17 @@ class AggressiveSplittingPlugin {
6262 apply ( compiler ) {
6363 compiler . plugin ( "compilation" , ( compilation ) => {
6464 compilation . plugin ( "optimize-chunks-advanced" , ( chunks ) => {
65- let i , chunk , newChunk ;
6665 const savedSplits = compilation . records && compilation . records . aggressiveSplits || [ ] ;
67- let usedSplits = savedSplits ;
68- if ( compilation . _aggressiveSplittingSplits )
69- usedSplits = usedSplits . concat ( compilation . _aggressiveSplittingSplits ) ;
66+ const usedSplits = compilation . _aggressiveSplittingSplits ?
67+ usedSplits . concat ( compilation . _aggressiveSplittingSplits ) : savedSplits ;
68+
7069 const minSize = this . options . minSize ;
7170 const maxSize = this . options . maxSize ;
7271 // 1. try to restore to recorded splitting
7372 for ( let j = 0 ; j < usedSplits . length ; j ++ ) {
7473 const splitData = usedSplits [ j ] ;
75- for ( i = 0 ; i < chunks . length ; i ++ ) {
76- chunk = chunks [ i ] ;
74+ for ( let i = 0 ; i < chunks . length ; i ++ ) {
75+ const chunk = chunks [ i ] ;
7776 const chunkModuleNames = chunk . modules . map ( makeRelative ( compiler . context ) ) ;
7877
7978 if ( chunkModuleNames . length < splitData . modules )
@@ -85,7 +84,7 @@ class AggressiveSplittingPlugin {
8584 if ( hasAllModules ) {
8685 if ( chunkModuleNames . length > splitData . modules . length ) {
8786 const selectedModules = moduleIndicies . map ( toChunkModuleIndices ( chunk . modules ) ) ;
88- newChunk = compilation . addChunk ( ) ;
87+ const newChunk = compilation . addChunk ( ) ;
8988 selectedModules . forEach ( moveModuleBetween ( chunk , newChunk ) ) ;
9089 chunk . split ( newChunk ) ;
9190 chunk . name = null ;
@@ -106,11 +105,11 @@ class AggressiveSplittingPlugin {
106105 }
107106 }
108107 // 2. for any other chunk which isn't splitted yet, split it
109- for ( i = 0 ; i < chunks . length ; i ++ ) {
110- chunk = chunks [ i ] ;
108+ for ( let i = 0 ; i < chunks . length ; i ++ ) {
109+ const chunk = chunks [ i ] ;
111110 const size = chunk . size ( this . options ) ;
112111 if ( size > maxSize && chunk . modules . length > 1 ) {
113- newChunk = compilation . addChunk ( ) ;
112+ const newChunk = compilation . addChunk ( ) ;
114113 const modules = chunk . modules
115114 . filter ( isNotAEntryModule ( chunk . entryModule ) )
116115 . sort ( ( a , b ) => {
@@ -172,7 +171,7 @@ class AggressiveSplittingPlugin {
172171 id : chunk . id
173172 } ) ;
174173 } else {
175- let splitData = records . aggressiveSplits [ chunk . _fromAggressiveSplittingIndex ] ;
174+ const splitData = records . aggressiveSplits [ chunk . _fromAggressiveSplittingIndex ] ;
176175 if ( splitData . hash !== chunk . hash || incorrectSize ) {
177176 if ( chunk . _fromAggressiveSplitting ) {
178177 chunk . _aggressiveSplittingInvalid = true ;
0 commit comments