Skip to content

Comments

perf: optimize bundle size via safe terser options#13244

Merged
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
kamja44:perf/optimize-bundle-size-terser
Jan 9, 2026
Merged

perf: optimize bundle size via safe terser options#13244
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
kamja44:perf/optimize-bundle-size-terser

Conversation

@kamja44
Copy link
Contributor

@kamja44 kamja44 commented Jan 9, 2026

Closes #13243

Changes

This PR optimizes the bundle size by tuning the Rollup > Terser configuration in scripts/rollup/createRollupConfig.js. The changes are focused on safe compression options that do not alter internal logic or break backward compatibility.

  • Enable ecma: 2020: Utilizes modern syntax (e.g., arrow functions, method shorthands) which results in smaller code output compared to ES5.
  • Increase passes to 4: Allows Terser to perform more iterations of compression for better results.
  • Enable toplevel compression: Removes unused variables in the top-level scope.
  • Enable booleans_as_integers: Optimizes true/false to 1/0.
  • Enable unsafe_arrows & unsafe_methods: safely converts functions to shorter arrow/method syntax in modern environments.

Result (Bundlewatch)

File Before After Difference
dist/index.cjs.js ~11.22KB 11.19KB -0.03KB

Verified that pnpm bundlewatch passes within the 11.25KB limit with a slightly larger safety margin.

Checklist

  • I have performed a self-review of my code
  • I have verified the bundle size using pnpm bundlewatch
  • I have verified that existing tests pass using pnpm test

@bluebill1049 bluebill1049 merged commit e26f886 into react-hook-form:master Jan 9, 2026
6 checks passed
bluebill1049 added a commit that referenced this pull request Jan 13, 2026
* fix #13250 issue with booleans_as_integers

* Revert "👌 chore: optimize bundle size via safe terser options (#13243) (#13244)"

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Optimize bundle size by tuning Terser compression options

2 participants