22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5+ "use strict" ;
6+
57function chunkContainsModule ( chunk , module ) {
6- var chunks = module . chunks ;
7- var modules = chunk . modules ;
8+ const chunks = module . chunks ;
9+ const modules = chunk . modules ;
810 if ( chunks . length < modules . length ) {
911 return chunks . indexOf ( chunk ) >= 0 ;
1012 } else {
@@ -15,35 +17,35 @@ function chunkContainsModule(chunk, module) {
1517function hasModule ( chunk , module , checkedChunks ) {
1618 if ( chunkContainsModule ( chunk , module ) ) return [ chunk ] ;
1719 if ( chunk . parents . length === 0 ) return false ;
18- return allHaveModule ( chunk . parents . filter ( function ( c ) {
20+ return allHaveModule ( chunk . parents . filter ( ( c ) => {
1921 return checkedChunks . indexOf ( c ) < 0 ;
2022 } ) , module , checkedChunks ) ;
2123}
2224
2325function allHaveModule ( someChunks , module , checkedChunks ) {
2426 if ( ! checkedChunks ) checkedChunks = [ ] ;
25- var chunks = [ ] ;
27+ let chunks = [ ] ;
2628 for ( var i = 0 ; i < someChunks . length ; i ++ ) {
2729 checkedChunks . push ( someChunks [ i ] ) ;
28- var subChunks = hasModule ( someChunks [ i ] , module , checkedChunks ) ;
30+ const subChunks = hasModule ( someChunks [ i ] , module , checkedChunks ) ;
2931 if ( ! subChunks ) return false ;
3032 addToSet ( chunks , subChunks ) ;
3133 }
3234 return chunks ;
3335}
3436
3537function addToSet ( set , items ) {
36- items . forEach ( function ( item ) {
38+ items . forEach ( ( item ) => {
3739 if ( set . indexOf ( item ) < 0 )
3840 set . push ( item ) ;
3941 } ) ;
4042}
4143
4244function debugIds ( chunks ) {
43- var list = chunks . map ( function ( chunk ) {
45+ const list = chunks . map ( ( chunk ) => {
4446 return chunk . debugId ;
4547 } ) ;
46- var debugIdMissing = list . some ( function ( dId ) {
48+ const debugIdMissing = list . some ( ( dId ) => {
4749 return typeof dId !== "number" ;
4850 } ) ;
4951 if ( debugIdMissing )
@@ -52,29 +54,29 @@ function debugIds(chunks) {
5254 return list . join ( "," ) ;
5355}
5456
55- function RemoveParentModulesPlugin ( ) { }
56- module . exports = RemoveParentModulesPlugin ;
57-
58- RemoveParentModulesPlugin . prototype . apply = function ( compiler ) {
59- compiler . plugin ( "compilation" , function ( compilation ) {
60- compilation . plugin ( [ "optimize-chunks-basic" , "optimize-extracted-chunks-basic" ] , function ( chunks ) {
61- chunks . forEach ( function ( chunk ) {
62- var cache = { } ;
63- chunk . modules . slice ( ) . forEach ( function ( module ) {
64- if ( chunk . parents . length === 0 ) return ;
65- var dId = "$" + debugIds ( module . chunks ) ;
66- var parentChunksWithModule ;
67- if ( ( dId in cache ) && dId !== "$no" ) {
68- parentChunksWithModule = cache [ dId ] ;
69- } else {
70- parentChunksWithModule = cache [ dId ] = allHaveModule ( chunk . parents , module ) ;
71- }
72- if ( parentChunksWithModule ) {
73- module . rewriteChunkInReasons ( chunk , parentChunksWithModule ) ;
74- chunk . removeModule ( module ) ;
75- }
57+ class RemoveParentModulesPlugin {
58+ apply ( compiler ) {
59+ compiler . plugin ( "compilation" , ( compilation ) => {
60+ compilation . plugin ( [ "optimize-chunks-basic" , "optimize-extracted-chunks-basic" ] , ( chunks ) => {
61+ chunks . forEach ( ( chunk ) => {
62+ const cache = { } ;
63+ chunk . modules . slice ( ) . forEach ( ( module ) => {
64+ if ( chunk . parents . length === 0 ) return ;
65+ const dId = "$" + debugIds ( module . chunks ) ;
66+ let parentChunksWithModule ;
67+ if ( ( dId in cache ) && dId !== "$no" ) {
68+ parentChunksWithModule = cache [ dId ] ;
69+ } else {
70+ parentChunksWithModule = cache [ dId ] = allHaveModule ( chunk . parents , module ) ;
71+ }
72+ if ( parentChunksWithModule ) {
73+ module . rewriteChunkInReasons ( chunk , parentChunksWithModule ) ;
74+ chunk . removeModule ( module ) ;
75+ }
76+ } ) ;
7677 } ) ;
7778 } ) ;
7879 } ) ;
79- } ) ;
80- } ;
80+ }
81+ }
82+ module . exports = RemoveParentModulesPlugin ;
0 commit comments