File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -502,6 +502,39 @@ export function composeDecoratorsConfig(
502
502
} ;
503
503
}
504
504
505
+ export function composePrintFileSizeConfig (
506
+ bundle : LibConfig [ 'bundle' ] ,
507
+ target : RsbuildConfigOutputTarget ,
508
+ ) : EnvironmentConfig {
509
+ if ( bundle ) {
510
+ return { } ;
511
+ }
512
+
513
+ // do not need to print detailed file size in bundleless mode
514
+ return {
515
+ performance : {
516
+ printFileSize : {
517
+ total : ( {
518
+ environmentName,
519
+ distPath,
520
+ assets,
521
+ totalSize,
522
+ totalGzipSize,
523
+ } ) => {
524
+ let log = `${ color . yellow ( assets . length ) } files generated in ${ color . blue ( distPath ) } ${ color . dim ( `(${ environmentName } )` ) } ` ;
525
+ log += '\n' ;
526
+ log += `${ color . magenta ( 'Total size:' ) } ${ ( totalSize / 1000 ) . toFixed ( 1 ) } kB` ;
527
+ if ( target === 'web' ) {
528
+ log += ` ${ color . green ( `(${ ( totalGzipSize / 1000 ) . toFixed ( 1 ) } kB gzipped)` ) } ` ;
529
+ }
530
+ return log ;
531
+ } ,
532
+ detail : false ,
533
+ } ,
534
+ } ,
535
+ } ;
536
+ }
537
+
505
538
export async function createConstantRsbuildConfig ( ) : Promise < EnvironmentConfig > {
506
539
// When the default configuration is inconsistent with rsbuild, remember to modify the type hints
507
540
// see https://github.com/web-infra-dev/rslib/discussions/856
@@ -1633,6 +1666,7 @@ async function composeLibRsbuildConfig(
1633
1666
compilerOptions ,
1634
1667
config . source ?. decorators ?. version ,
1635
1668
) ;
1669
+ const printFileSizeConfig = composePrintFileSizeConfig ( bundle , target ) ;
1636
1670
1637
1671
return mergeRsbuildConfig (
1638
1672
formatConfig ,
@@ -1662,6 +1696,7 @@ async function composeLibRsbuildConfig(
1662
1696
dtsConfig ,
1663
1697
bannerFooterConfig ,
1664
1698
decoratorsConfig ,
1699
+ printFileSizeConfig ,
1665
1700
) ;
1666
1701
}
1667
1702
You can’t perform that action at this time.
0 commit comments