@@ -25,7 +25,7 @@ export function formatSize(size: number): string {
25
25
return `${ + ( size / Math . pow ( 1024 , index ) ) . toPrecision ( 3 ) } ${ abbreviations [ index ] } ` ;
26
26
}
27
27
28
- export type BundleStatsData = [ files : string , names : string , size : string ] ;
28
+ export type BundleStatsData = [ files : string , names : string , size : number | string ] ;
29
29
30
30
export interface BundleStats {
31
31
initial : boolean ;
@@ -43,35 +43,36 @@ export function generateBundleStats(
43
43
} ,
44
44
colors : boolean ,
45
45
) : BundleStats {
46
- const g = ( x : string ) => ( colors ? ansiColors . greenBright ( x ) : x ) ;
47
- const c = ( x : string ) => ( colors ? ansiColors . cyanBright ( x ) : x ) ;
48
-
49
- const size = typeof info . size === 'number' ? formatSize ( info . size ) : '-' ;
46
+ const size = typeof info . size === 'number' ? info . size : '-' ;
50
47
const files = info . files . filter ( f => ! f . endsWith ( '.map' ) ) . map ( f => path . basename ( f ) ) . join ( ', ' ) ;
51
48
const names = info . names ?. length ? info . names . join ( ', ' ) : '-' ;
52
49
const initial = ! ! ( info . entry || info . initial ) ;
53
50
54
51
return {
55
52
initial,
56
- stats : [ g ( files ) , names , c ( size ) ] ,
53
+ stats : [ files , names , size ] ,
57
54
}
58
55
}
59
56
60
57
function generateBuildStatsTable ( data : BundleStats [ ] , colors : boolean ) : string {
58
+ const g = ( x : string ) => colors ? ansiColors . greenBright ( x ) : x ;
59
+ const c = ( x : string ) => colors ? ansiColors . cyanBright ( x ) : x ;
60
+ const bold = ( x : string ) => colors ? ansiColors . bold ( x ) : x ;
61
+ const dim = ( x : string ) => colors ? ansiColors . dim ( x ) : x ;
62
+
61
63
const changedEntryChunksStats : BundleStatsData [ ] = [ ] ;
62
64
const changedLazyChunksStats : BundleStatsData [ ] = [ ] ;
65
+
63
66
for ( const { initial, stats } of data ) {
64
- if ( initial ) {
65
- changedEntryChunksStats . push ( stats ) ;
66
- } else {
67
- changedLazyChunksStats . push ( stats ) ;
68
- }
67
+ const [ files , names , size ] = stats ;
68
+ ( initial ? changedEntryChunksStats : changedLazyChunksStats ) . push ( [
69
+ g ( files ) ,
70
+ names ,
71
+ c ( typeof size === 'string' ? size : formatSize ( size ) ) ,
72
+ ] ) ;
69
73
}
70
74
71
- const bundleInfo : string [ ] [ ] = [ ] ;
72
-
73
- const bold = ( x : string ) => colors ? ansiColors . bold ( x ) : x ;
74
- const dim = ( x : string ) => colors ? ansiColors . dim ( x ) : x ;
75
+ const bundleInfo : ( string | number ) [ ] [ ] = [ ] ;
75
76
76
77
// Entry chunks
77
78
if ( changedEntryChunksStats . length ) {
@@ -124,6 +125,19 @@ function statsToString(json: any, statsConfig: any, bundleState?: BundleStats[])
124
125
unchangedChunkNumber = json . chunks . length - changedChunksStats . length ;
125
126
}
126
127
128
+ // Sort chunks by size in descending order
129
+ changedChunksStats . sort ( ( a , b ) => {
130
+ if ( a . stats [ 2 ] > b . stats [ 2 ] ) {
131
+ return - 1 ;
132
+ }
133
+
134
+ if ( a . stats [ 2 ] < b . stats [ 2 ] ) {
135
+ return 1 ;
136
+ }
137
+
138
+ return 0 ;
139
+ } ) ;
140
+
127
141
const statsTable = generateBuildStatsTable ( changedChunksStats , colors ) ;
128
142
129
143
// In some cases we do things outside of webpack context
0 commit comments