@@ -7,31 +7,43 @@ export function generateComponentBundles(
77 config : d . Config ,
88 buildCtx : d . BuildCtx ,
99) : d . ComponentCompilerMeta [ ] [ ] {
10- let cmps = buildCtx . components ;
10+ const cmps = sortBy ( buildCtx . components , cmp => cmp . dependants . length ) ;
1111 if ( config . devMode ) {
12- return cmps . map ( cmp => [ cmp ] ) ;
12+ const devCmps = ( config . excludeUnusedDependencies )
13+ ? filterUnusedDependencies ( cmps , cmps )
14+ : cmps ;
15+
16+ return devCmps . map ( cmp => [ cmp ] ) ;
1317 }
1418
1519 const defaultBundles = getDefaultBundles ( config , buildCtx , cmps ) ;
1620
17- cmps = sortBy ( cmps , cmp => cmp . dependants . length ) ;
18-
1921 // Visit components that are already in one of the default bundlers
2022 const visited = new Set ( ) ;
2123 defaultBundles . forEach ( entry => {
2224 entry . forEach ( cmp => visited . add ( cmp ) ) ;
2325 } ) ;
2426
25- const bundlers : d . ComponentCompilerMeta [ ] [ ] = cmps
26- . filter ( cmp => ! visited . has ( cmp ) )
27- . map ( cmp => [ cmp ] ) ;
27+ let remainingComponents : d . ComponentCompilerMeta [ ] = cmps
28+ . filter ( cmp => ! visited . has ( cmp ) ) ;
2829
30+ if ( config . excludeUnusedDependencies ) {
31+ remainingComponents = filterUnusedDependencies ( remainingComponents , cmps ) ;
32+ }
33+
34+ const bundlers = remainingComponents . map ( c => [ c ] ) ;
2935 return [
3036 ...defaultBundles ,
3137 ...optimizeBundlers ( bundlers , 0.6 )
3238 ] . filter ( b => b . length > 0 ) ;
3339}
3440
41+ function filterUnusedDependencies ( remainingComponents : d . ComponentCompilerMeta [ ] , allCmps : d . ComponentCompilerMeta [ ] ) {
42+ return remainingComponents . filter ( c => (
43+ ! c . isCollectionDependency ||
44+ c . dependants . some ( dep => allCmps . some ( c => c . tagName === dep && ! c . isCollectionDependency ) )
45+ ) ) ;
46+ }
3547
3648function optimizeBundlers ( bundles : d . ComponentCompilerMeta [ ] [ ] , threshold : number ) {
3749 const cmpIndexMap = new Map < string , number > ( ) ;
0 commit comments