@@ -406,14 +406,19 @@ export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
406406 return ;
407407 }
408408
409+ const environments = context . environmentList . filter (
410+ ( { config } ) => config . performance . printFileSize !== false ,
411+ ) ;
412+
413+ // If no environment has printFileSize enabled, skip
414+ if ( ! environments . length ) {
415+ return ;
416+ }
417+
409418 // Check if any environment has diff enabled
410- const showDiff = context . environmentList . some ( ( environment ) => {
419+ const showDiff = environments . some ( ( environment ) => {
411420 const { printFileSize } = environment . config . performance ;
412- if ( typeof printFileSize === 'boolean' ) {
413- // uses default (false)
414- return false ;
415- }
416- return Boolean ( printFileSize . diff ) ;
421+ return typeof printFileSize === 'object' && Boolean ( printFileSize . diff ) ;
417422 } ) ;
418423
419424 // Load previous build sizes for comparison (only if diff is enabled)
@@ -422,22 +427,15 @@ export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
422427 : { } ;
423428 const newCache : FileSizeCache = { } ;
424429
425- const logs : string [ ] = [ ] ;
426-
427- await Promise . all (
428- context . environmentList . map ( async ( environment , index ) => {
429- const { printFileSize } = environment . config . performance ;
430-
431- if ( printFileSize === false ) {
432- return ;
433- }
434-
430+ const logs = await Promise . all (
431+ environments . map ( async ( { name, index, config, distPath } ) => {
432+ const { printFileSize } = config . performance ;
435433 const defaultConfig : PrintFileSizeOptions = {
436434 total : true ,
437435 detail : true ,
438436 diff : false ,
439437 // print compressed size for the browser targets by default
440- compressed : environment . config . output . target !== 'node' ,
438+ compressed : config . output . target !== 'node' ,
441439 } ;
442440
443441 const mergedConfig =
@@ -453,24 +451,26 @@ export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
453451 mergedConfig ,
454452 statsItem ,
455453 api . context . rootPath ,
456- environment . distPath ,
457- environment . name ,
454+ distPath ,
455+ name ,
458456 previousSizes ,
459457 ) ;
460458
461- logs . push ( ...statsLogs ) ;
462-
463459 // Store current sizes for this environment
464- newCache [ environment . name ] = currentSizes ;
460+ newCache [ name ] = currentSizes ;
461+
462+ return statsLogs . join ( '\n' ) ;
465463 } ) ,
466464 ) . catch ( ( err : unknown ) => {
467465 logger . warn ( 'Failed to print file size.' ) ;
468466 logger . warn ( err ) ;
469467 } ) ;
470468
471- logger . log ( logs . join ( '\n' ) ) ;
469+ if ( logs ) {
470+ logger . log ( logs . join ( '\n' ) ) ;
471+ }
472472
473- // Save current sizes for next build comparison (only if showDiff is enabled)
473+ // Save current sizes for next build comparison (only if diff is enabled)
474474 if ( showDiff ) {
475475 await saveSizes ( api . context . cachePath , newCache ) ;
476476 }
0 commit comments