@@ -52,46 +52,41 @@ class ModuleConcatenationPlugin {
5252 if ( ! module . reasons . every ( reason => reason . dependency instanceof HarmonyImportDependency ) )
5353 return false ;
5454
55- // It must be statically known which exports are provided or used
56- if ( ! Array . isArray ( module . providedExports ) )
57- return false ;
58-
5955 return true ;
6056 } ) ) ;
61- const possibleRoots = relevantModules . filter ( module => {
62- return true ;
63- } ) ;
6457 const concatConfigurations = [ ] ;
65- while ( possibleRoots . length ) {
66- const currentRoot = possibleRoots . pop ( ) ;
67- // console.log("#process", currentRoot.debugId, currentRoot.resource);
58+ for ( const currentRoot of relevantModules ) {
6859 const currentConfiguration = new ConcatConfiguration ( currentRoot ) ;
6960 for ( const imp of this . getImports ( currentRoot ) ) {
7061 this . tryToAdd ( currentConfiguration , imp , possibleInners ) ;
7162 }
7263 if ( ! currentConfiguration . isEmpty ( ) )
7364 concatConfigurations . push ( currentConfiguration ) ;
7465 }
66+ // HACK: Sort configurations by length and start with the longest one
67+ // to get the biggers groups possible. Used modules are marked with usedModules
68+ // TODO: Allow to reuse existing configuration while trying to add dependencies.
69+ // This would improve performance. O(n^2) -> O(n)
7570 concatConfigurations . sort ( ( a , b ) => {
7671 return b . modules . size - a . modules . size ;
7772 } ) ;
7873 const usedModules = new Set ( ) ;
79- for ( const config of concatConfigurations ) {
80- if ( usedModules . has ( config . rootModule ) )
74+ for ( const concatConfiguration of concatConfigurations ) {
75+ if ( usedModules . has ( concatConfiguration . rootModule ) )
8176 continue ;
8277 const orderedModules = new Set ( ) ;
83- this . addInOrder ( config . rootModule , config . modules , orderedModules ) ;
84- const newModule = new ConcatenatedModule ( config . rootModule , Array . from ( orderedModules ) ) ;
78+ this . addInOrder ( concatConfiguration . rootModule , concatConfiguration . modules , orderedModules ) ;
79+ const newModule = new ConcatenatedModule ( concatConfiguration . rootModule , Array . from ( orderedModules ) ) ;
8580 for ( const m of orderedModules ) {
8681 usedModules . add ( m ) ;
8782 chunk . removeModule ( m ) ;
8883 }
8984 chunk . addModule ( newModule ) ;
9085 compilation . modules . push ( newModule ) ;
91- if ( chunk . entryModule === config . rootModule )
86+ if ( chunk . entryModule === concatConfiguration . rootModule )
9287 chunk . entryModule = newModule ;
93- config . rootModule . reasons . forEach ( reason => {
94- if ( ! config . modules . has ( reason . module ) )
88+ concatConfiguration . rootModule . reasons . forEach ( reason => {
89+ if ( ! concatConfiguration . modules . has ( reason . module ) )
9590 reason . dependency . module = newModule ;
9691 } ) ;
9792 }
0 commit comments