@@ -157,12 +157,12 @@ async function printFileSizes(
157157 rootPath : string ,
158158 distPath : string ,
159159 environmentName : string ,
160- previousSizes : FileSizeCache ,
160+ previousSizes : FileSizeCache | null ,
161161) {
162162 const logs : string [ ] = [ ] ;
163163 const showDetail = options . detail !== false ;
164+ const showDiff = options . diff !== false && previousSizes !== null ;
164165 let showTotal = options . total !== false ;
165- const showDiff = options . diff === true ;
166166
167167 if ( ! showTotal && ! showDetail ) {
168168 return { logs, currentSizes : { } } ;
@@ -180,43 +180,39 @@ async function printFileSizes(
180180 const size = Buffer . byteLength ( contents ) ;
181181 const compressible = options . compressed && isCompressible ( fileName ) ;
182182 const gzippedSize = compressible ? await gzipSize ( contents ) : null ;
183- const gzipSizeLabel = gzippedSize
184- ? getAssetColor ( gzippedSize ) ( calcFileSize ( gzippedSize ) )
185- : null ;
186183
187184 // Normalize filename for comparison (remove hash)
188185 const normalizedName = normalizeFileName ( fileName ) ;
189- const previousSizeData = previousSizes [ environmentName ] ?. [ normalizedName ] ;
190- const previousSize = previousSizeData ?. size ;
191-
192- // Calculate size differences for inline display
193- let sizeDiff : number | null = null ;
194- let gzipDiff : number | null = null ;
195- if ( showDiff && previousSize !== undefined ) {
196- sizeDiff = size - previousSize ;
197- if ( gzippedSize && previousSizeData ?. gzippedSize !== undefined ) {
198- gzipDiff = gzippedSize - previousSizeData . gzippedSize ;
199- }
200- }
201186
202187 // Store current size for next build
203188 currentSizes [ normalizedName ] = {
204189 size,
205190 gzippedSize : gzippedSize ?? undefined ,
206191 } ;
207192
208- const isNew = showDiff && previousSize === undefined ;
209-
210193 // Append inline diff to sizeLabel
211194 let sizeLabel = calcFileSize ( size ) ;
212195 let sizeLabelLength = sizeLabel . length ;
213- if ( isNew ) {
214- sizeLabel += ` ${ color . cyan ( '(NEW)' ) } ` ;
215- sizeLabelLength += 6 ;
216- } else if ( sizeDiff !== null && sizeDiff !== 0 ) {
217- const { label, length } = formatDiff ( sizeDiff ) ;
218- sizeLabel += ` ${ label } ` ;
219- sizeLabelLength += length + 1 ;
196+ let gzipSizeLabel = gzippedSize
197+ ? getAssetColor ( gzippedSize ) ( calcFileSize ( gzippedSize ) )
198+ : null ;
199+
200+ // Calculate size differences for inline display
201+ if ( showDiff ) {
202+ const sizeData = previousSizes [ environmentName ] ?. [ normalizedName ] ;
203+ const sizeDiff = size - ( sizeData ?. size ?? 0 ) ;
204+ if ( sizeDiff !== 0 ) {
205+ const { label, length } = formatDiff ( sizeDiff ) ;
206+ sizeLabel += ` ${ label } ` ;
207+ sizeLabelLength += length + 1 ;
208+ }
209+
210+ if ( gzippedSize ) {
211+ const gzipDiff = gzippedSize - ( sizeData ?. gzippedSize ?? 0 ) ;
212+ if ( gzipDiff !== 0 ) {
213+ gzipSizeLabel += ` ${ formatDiff ( gzipDiff ) . label } ` ;
214+ }
215+ }
220216 }
221217
222218 return {
@@ -227,8 +223,6 @@ async function printFileSizes(
227223 name : path . basename ( fileName ) ,
228224 gzippedSize,
229225 gzipSizeLabel,
230- gzipDiff,
231- isNew,
232226 } ;
233227 } ;
234228
@@ -317,15 +311,9 @@ async function printFileSizes(
317311 ) ;
318312
319313 for ( const asset of assets ) {
320- let { sizeLabel, sizeLabelLength, gzipSizeLabel, gzipDiff, isNew } =
321- asset ;
314+ let { sizeLabel, sizeLabelLength, gzipSizeLabel } = asset ;
322315 const { name, folder } = asset ;
323316
324- // Append inline diff to gzipSizeLabel (only for existing files with changes)
325- if ( gzipSizeLabel && ! isNew && gzipDiff !== null && gzipDiff !== 0 ) {
326- gzipSizeLabel += ` ${ formatDiff ( gzipDiff ) . label } ` ;
327- }
328-
329317 const fileNameLength = ( folder + path . sep + name ) . length ;
330318
331319 let fileNameLabel =
@@ -424,7 +412,7 @@ export const pluginFileSize = (context: InternalContext): RsbuildPlugin => ({
424412 // Load previous build sizes for comparison (only if diff is enabled)
425413 const previousSizes = showDiff
426414 ? await loadPreviousSizes ( api . context . cachePath )
427- : { } ;
415+ : null ;
428416 const newCache : FileSizeCache = { } ;
429417
430418 const logs = await Promise . all (
0 commit comments