Skip to content

feat: implement bundle size budget enforcement for client app#749

Merged
Calebux merged 1 commit into
Calebux:mainfrom
somotochukwu-dev:tighten-bundle-size-697
May 28, 2026
Merged

feat: implement bundle size budget enforcement for client app#749
Calebux merged 1 commit into
Calebux:mainfrom
somotochukwu-dev:tighten-bundle-size-697

Conversation

@somotochukwu-dev
Copy link
Copy Markdown

Tighten bundle-size budgets for the client app

Closes #697

Summary

Replaces the broken, rudimentary bundle-size CI (pnpm-based du -sk measurement) with route-level and chunk-level budget enforcement for the client app.

Changes

New files:

  • client/bundle-size.json — Budget definitions: total JS (800 KB), shared chunks (400 KB), per-route limits (150–350 KB), per-chunk limit (200 KB)
  • client/bundle-size.schema.json — JSON Schema for IDE support
  • client/scripts/check-bundle-size.js — Reads Next.js build manifest, resolves per-route JS chunks, measures actual file sizes, and compares against budgets. Exits 1 on violations. Supports --json and --root= flags
  • client/__tests__/lib/check-bundle-size.test.ts — 19 unit tests covering core logic

Modified files:

  • client/package.json — Added @next/bundle-analyzer devDep + check-bundle-size npm script
  • client/next.config.mjs — Conditionally wraps config with bundle analyzer when ANALYZE=true
  • .github/workflows/bundle-size.yml — Rewrote to: build from client/ with npm ci, run check script, post per-route PR comment, fail CI on violations
  • client/docs/TEST_INFRASTRUCTURE.md — Added bundle-size workflow docs
  • docs/repo-issue-backlog-2026-05.md — Added issue [P2] Tighten bundle-size budgets for the client app #697 resolution notes

Testing

  • npm run check-bundle-size runs the checker
  • ANALYZE=true npm run build && node scripts/check-bundle-size.js runs full check locally
  • 19 new unit tests pass (__tests__/lib/check-bundle-size.test.ts)
  • Existing tests unaffected

CI Behavior

  • On every PR to main/develop: build with ANALYZE=true, enforce budgets, post detailed comment with per-route breakdown
  • Violations block merge; warnings at 90%+ budget usage trigger alerts
  • Exceptions require team review (update bundle-size.json in a separate commit)

- Added `@next/bundle-analyzer` to devDependencies and integrated it into `next.config.mjs` for analyzing bundle sizes.
- Created `client/bundle-size.json` to define size budgets for total, shared, per-route, and per-chunk JS sizes.
- Developed `client/scripts/check-bundle-size.js` to measure actual bundle sizes against defined budgets and report violations.
- Updated CI workflow to enforce bundle size checks on PRs to `main` and `develop`.
- Added unit tests for the bundle size checking logic in `client/__tests__/lib/check-bundle-size.test.ts`.
- Documented the bundle size budget enforcement process in `client/docs/TEST_INFRASTRUCTURE.md`.
- Created JSON schema for bundle size configuration in `client/bundle-size.schema.json`.
@somotochukwu-dev somotochukwu-dev requested a review from Calebux as a code owner May 28, 2026 09:40
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@somotochukwu-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Calebux Calebux merged commit 46cefef into Calebux:main May 28, 2026
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.

[P2] Tighten bundle-size budgets for the client app

3 participants