Skip to content

Conversation

@lluisemper
Copy link

Add showDiff option to printFileSize for build-to-build size comparison

Add a new showDiff option to performance.printFileSize that displays file size changes compared to the previous build. This helps developers track how their changes affect bundle sizes over time.

Summary

Adds a showDiff option to performance.printFileSize that displays file size changes between builds. Shows color-coded differences (red for increases, green for decreases, "NEW" for new files) in a dedicated "Diff" column. Caches previous build sizes in node_modules/.cache/rsbuild/ for comparison, with automatic hash normalization to match files across builds. Opt-in feature (disabled by default).

E.G.
Screenshot 2025-11-23 at 19 25 32

Related Links

#6100

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

…ize comparison

Add a new `showDiff` option to performance.printFileSize that displays file size changes compared to the previous build. This helps developers track how their changes affect bundle sizes over time.
Copilot AI review requested due to automatic review settings November 23, 2025 19:00
@netlify
Copy link

netlify bot commented Nov 23, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 69ccbe4
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/692362138c094100083ee859
😎 Deploy Preview https://deploy-preview-6635--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 59 (🔴 down 10 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@CLAassistant
Copy link

CLAassistant commented Nov 23, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new showDiff option to performance.printFileSize that displays file size changes between builds. The feature helps developers track how their changes affect bundle sizes by showing color-coded differences (red for increases, green for decreases, "NEW" for new files) in a dedicated "Diff" column. The implementation caches build sizes in node_modules/.cache/rsbuild/ and uses hash normalization to match files across builds. The feature is opt-in and disabled by default.

Key changes:

  • Adds showDiff boolean option to PrintFileSizeOptions type
  • Implements file size caching mechanism with hash normalization for cross-build file matching
  • Updates output formatting to include a conditional "Diff" column with color-coded size changes

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
website/docs/en/config/performance/print-file-size.mdx Documents the new showDiff option with examples showing the diff column output
packages/core/tests/fileSize.test.ts Adds comprehensive test coverage for the normalizeFileName function and updates asset exclusion tests
packages/core/src/types/config.ts Adds showDiff boolean property to PrintFileSizeOptions interface
packages/core/src/plugins/fileSize.ts Implements core diff functionality including cache management, file name normalization, and diff column rendering

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that create-react-app's logging style is more concise. It does not add an extra “Diff” column but instead shows size changes in parentheses right after the existing size.

This makes the format more flexible, so we could also show the diff for the gzip size if we want.

Image

return path.join(
rootPath,
'node_modules',
'.cache',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use api.context.cachePath to replace rootPath/node_modules/.cache, see https://rsbuild.rs/api/javascript-api/instance#contextcachepath

const sign = diffSize > 0 ? '+' : '-';
diffText = `${sign}${diffStr}`;
} else {
diffText = '0 kB';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we omit the 0 kB? It seems like unnecessary information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants