@@ -29,9 +29,12 @@ export function formatSize(size: number): string {
29
29
30
30
export type BundleStatsData = [ files : string , names : string , size : number | string ] ;
31
31
32
+ export type ChunkType = 'modern' | 'legacy' | 'unknown' ;
33
+
32
34
export interface BundleStats {
33
35
initial : boolean ;
34
36
stats : BundleStatsData ;
37
+ chunkType : ChunkType ;
35
38
} ;
36
39
37
40
export function generateBundleStats (
@@ -42,15 +45,17 @@ export function generateBundleStats(
42
45
entry : boolean ;
43
46
initial : boolean ;
44
47
rendered ?: boolean ;
48
+ chunkType ?: ChunkType ,
45
49
} ,
46
- colors : boolean ,
47
50
) : BundleStats {
48
51
const size = typeof info . size === 'number' ? info . size : '-' ;
49
52
const files = info . files . filter ( f => ! f . endsWith ( '.map' ) ) . map ( f => path . basename ( f ) ) . join ( ', ' ) ;
50
53
const names = info . names ?. length ? info . names . join ( ', ' ) : '-' ;
51
54
const initial = ! ! ( info . entry || info . initial ) ;
55
+ const chunkType = info . chunkType || 'unknown' ;
52
56
53
57
return {
58
+ chunkType,
54
59
initial,
55
60
stats : [ files , names , size ] ,
56
61
}
@@ -65,9 +70,11 @@ function generateBuildStatsTable(data: BundleStats[], colors: boolean, showTotal
65
70
const changedEntryChunksStats : BundleStatsData [ ] = [ ] ;
66
71
const changedLazyChunksStats : BundleStatsData [ ] = [ ] ;
67
72
68
- let initialTotalSize = 0 ;
73
+ let initialModernTotalSize = 0 ;
74
+ let initialLegacyTotalSize = 0 ;
75
+ let modernFileSuffix : string | undefined ;
69
76
70
- for ( const { initial, stats } of data ) {
77
+ for ( const { initial, stats, chunkType } of data ) {
71
78
const [ files , names , size ] = stats ;
72
79
73
80
const data : BundleStatsData = [
@@ -80,9 +87,23 @@ function generateBuildStatsTable(data: BundleStats[], colors: boolean, showTotal
80
87
changedEntryChunksStats . push ( data ) ;
81
88
82
89
if ( typeof size === 'number' ) {
83
- initialTotalSize += size ;
90
+ switch ( chunkType ) {
91
+ case 'modern' :
92
+ initialModernTotalSize += size ;
93
+ if ( ! modernFileSuffix ) {
94
+ const match = files . match ( / - ( e s 2 0 \d { 2 } | e s n e x t ) / ) ;
95
+ modernFileSuffix = match ?. [ 1 ] . toString ( ) . toUpperCase ( ) ;
96
+ }
97
+ break ;
98
+ case 'legacy' :
99
+ initialLegacyTotalSize += size ;
100
+ break ;
101
+ default :
102
+ initialModernTotalSize += size ;
103
+ initialLegacyTotalSize += size ;
104
+ break ;
105
+ }
84
106
}
85
-
86
107
} else {
87
108
changedLazyChunksStats . push ( data ) ;
88
109
}
@@ -99,7 +120,14 @@ function generateBuildStatsTable(data: BundleStats[], colors: boolean, showTotal
99
120
100
121
if ( showTotalSize ) {
101
122
bundleInfo . push ( [ ] ) ;
102
- bundleInfo . push ( [ ' ' , 'Initial Total' , formatSize ( initialTotalSize ) ] . map ( bold ) ) ;
123
+ if ( initialModernTotalSize === initialLegacyTotalSize ) {
124
+ bundleInfo . push ( [ ' ' , 'Initial Total' , formatSize ( initialModernTotalSize ) ] . map ( bold ) ) ;
125
+ } else {
126
+ bundleInfo . push (
127
+ [ ' ' , 'Initial ES5 Total' , formatSize ( initialLegacyTotalSize ) ] . map ( bold ) ,
128
+ [ ' ' , `Initial ${ modernFileSuffix } Total` , formatSize ( initialModernTotalSize ) ] . map ( bold ) ,
129
+ ) ;
130
+ }
103
131
}
104
132
}
105
133
@@ -142,7 +170,7 @@ function statsToString(json: any, statsConfig: any, bundleState?: BundleStats[])
142
170
143
171
const assets = json . assets . filter ( ( asset : any ) => chunk . files . includes ( asset . name ) ) ;
144
172
const summedSize = assets . filter ( ( asset : any ) => ! asset . name . endsWith ( ".map" ) ) . reduce ( ( total : number , asset : any ) => { return total + asset . size } , 0 ) ;
145
- changedChunksStats . push ( generateBundleStats ( { ...chunk , size : summedSize } , colors ) ) ;
173
+ changedChunksStats . push ( generateBundleStats ( { ...chunk , size : summedSize } ) ) ;
146
174
}
147
175
unchangedChunkNumber = json . chunks . length - changedChunksStats . length ;
148
176
}
0 commit comments