22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5+ function chunkContainsModule ( chunk , module ) {
6+ var chunks = module . chunks ;
7+ var modules = chunk . modules ;
8+ if ( chunks . length > modules . length ) {
9+ return chunks . indexOf ( chunk ) >= 0 ;
10+ } else {
11+ return modules . indexOf ( module ) >= 0 ;
12+ }
13+ }
14+
515function hasModule ( chunk , module , checkedChunks ) {
6- if ( chunk . modules . indexOf ( module ) >= 0 ) return [ chunk ] ;
16+ if ( chunkContainsModule ( chunk , module ) ) return [ chunk ] ;
717 if ( chunk . entry ) return false ;
818 return allHaveModule ( chunk . parents . filter ( function ( c ) {
919 return checkedChunks . indexOf ( c ) < 0 ;
@@ -29,16 +39,34 @@ function addToSet(set, items) {
2939 } ) ;
3040}
3141
42+ function debugIds ( chunks ) {
43+ var list = chunks . map ( function ( chunk ) {
44+ return chunk . debugId ;
45+ } ) ;
46+ if ( list . some ( function ( dId ) {
47+ return typeof dId !== "number" ;
48+ } ) ) return "no" ;
49+ list . sort ( ) ;
50+ return list . join ( "," ) ;
51+ }
52+
3253function RemoveParentModulesPlugin ( ) { }
3354module . exports = RemoveParentModulesPlugin ;
3455
3556RemoveParentModulesPlugin . prototype . apply = function ( compiler ) {
3657 compiler . plugin ( "compilation" , function ( compilation ) {
3758 compilation . plugin ( [ "optimize-chunks-basic" , "optimize-extracted-chunks-basic" ] , function ( chunks ) {
3859 chunks . forEach ( function ( chunk ) {
60+ var cache = { } ;
3961 chunk . modules . slice ( ) . forEach ( function ( module ) {
4062 if ( chunk . entry ) return ;
41- var parentChunksWithModule = allHaveModule ( chunk . parents , module ) ;
63+ var dId = "$" + debugIds ( module . chunks ) ;
64+ var parentChunksWithModule ;
65+ if ( ( dId in cache ) && dId !== "$no" ) {
66+ parentChunksWithModule = cache [ dId ] ;
67+ } else {
68+ parentChunksWithModule = cache [ dId ] = allHaveModule ( chunk . parents , module ) ;
69+ }
4270 if ( parentChunksWithModule ) {
4371 module . rewriteChunkInReasons ( chunk , parentChunksWithModule ) ;
4472 chunk . removeModule ( module ) ;
0 commit comments