@@ -104,19 +104,12 @@ const getAssetColor = (size: number) => {
104104function getHeader (
105105 maxFileLength : number ,
106106 maxSizeLength : number ,
107- maxDiffLength : number ,
108107 fileHeader : string ,
109- showDiffHeader : boolean ,
110108 showGzipHeader : boolean ,
111109) {
112110 const lengths = [ maxFileLength , maxSizeLength ] ;
113111 const rowTypes = [ fileHeader , 'Size' ] ;
114112
115- if ( showDiffHeader ) {
116- rowTypes . push ( 'Diff' ) ;
117- lengths . push ( maxDiffLength ) ;
118- }
119-
120113 if ( showGzipHeader ) {
121114 rowTypes . push ( 'Gzip' ) ;
122115 }
@@ -169,7 +162,7 @@ async function printFileSizes(
169162 const logs : string [ ] = [ ] ;
170163 const showDetail = options . detail !== false ;
171164 let showTotal = options . total !== false ;
172- const showDiff = options . showDiff === true ;
165+ const showDiff = options . diff === true ;
173166
174167 if ( ! showTotal && ! showDetail ) {
175168 return { logs, currentSizes : { } } ;
@@ -320,14 +313,7 @@ async function printFileSizes(
320313 ) ;
321314
322315 logs . push (
323- getHeader (
324- maxFileLength ,
325- maxSizeLength ,
326- 0 ,
327- fileHeader ,
328- false ,
329- showGzipHeader ,
330- ) ,
316+ getHeader ( maxFileLength , maxSizeLength , fileHeader , showGzipHeader ) ,
331317 ) ;
332318
333319 for ( const asset of assets ) {
@@ -413,31 +399,33 @@ export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
413399 name : 'rsbuild:file-size' ,
414400
415401 setup ( api ) {
416- api . onAfterBuild ( async ( { stats, environments , isFirstCompile } ) => {
402+ api . onAfterBuild ( async ( { stats, isFirstCompile } ) => {
417403 const { hasErrors } = context . buildState ;
418404 // No need to print file sizes if there is any compilation error
419405 if ( ! stats || hasErrors || ! isFirstCompile ) {
420406 return ;
421407 }
422408
423- // Check if any environment has showDiff enabled
424- const hasShowDiff = Object . values ( environments ) . some ( ( environment ) => {
409+ // Check if any environment has diff enabled
410+ const showDiff = context . environmentList . some ( ( environment ) => {
425411 const { printFileSize } = environment . config . performance ;
426- if ( printFileSize === false ) return false ;
427- if ( printFileSize === true ) return false ; // uses default (false)
428- return printFileSize . showDiff === true ;
412+ if ( typeof printFileSize === 'boolean' ) {
413+ // uses default (false)
414+ return false ;
415+ }
416+ return Boolean ( printFileSize . diff ) ;
429417 } ) ;
430418
431- // Load previous build sizes for comparison (only if showDiff is enabled)
432- const previousSizes = hasShowDiff
419+ // Load previous build sizes for comparison (only if diff is enabled)
420+ const previousSizes = showDiff
433421 ? await loadPreviousSizes ( api . context . cachePath )
434422 : { } ;
435423 const newCache : FileSizeCache = { } ;
436424
437425 const logs : string [ ] = [ ] ;
438426
439427 await Promise . all (
440- Object . values ( environments ) . map ( async ( environment , index ) => {
428+ context . environmentList . map ( async ( environment , index ) => {
441429 const { printFileSize } = environment . config . performance ;
442430
443431 if ( printFileSize === false ) {
@@ -447,10 +435,9 @@ export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
447435 const defaultConfig : PrintFileSizeOptions = {
448436 total : true ,
449437 detail : true ,
438+ diff : false ,
450439 // print compressed size for the browser targets by default
451440 compressed : environment . config . output . target !== 'node' ,
452- // disable diff by default to avoid breaking existing output expectations
453- showDiff : false ,
454441 } ;
455442
456443 const mergedConfig =
@@ -484,7 +471,7 @@ export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
484471 logger . log ( logs . join ( '\n' ) ) ;
485472
486473 // Save current sizes for next build comparison (only if showDiff is enabled)
487- if ( hasShowDiff ) {
474+ if ( showDiff ) {
488475 await saveSizes ( api . context . cachePath , newCache ) ;
489476 }
490477 } ) ;
0 commit comments