chunkguard
v1.0.0
Published
PR-based bundle size guard for modern frontend apps
Readme
🛡 ChunkGuard
PR-based bundle size guard for modern frontend applications.
ChunkGuard helps teams detect bundle size increases before they reach production. It compares your current branch against a base branch, calculates compressed bundle size, and optionally fails CI if thresholds are exceeded.
🚀 Why ChunkGuard?
Frontend bundle bloat often goes unnoticed until:
- Lighthouse scores drop
- Performance metrics degrade
- Production monitoring alerts fire
ChunkGuard shifts that detection left into your pull request workflow.
✨ Features
- ✅ Compare bundle size against a base branch
- ✅ Gzip-based size calculation (realistic transfer size)
- ✅ CI-friendly exit codes
- ✅ Configurable size thresholds
- ✅ Clear terminal output
📦 Installation
Run via npx
npx chunkguard --max-increase 50Install as dev dependency
npm install --save-dev chunkguardThen run:
npx chunkguard🛠 Usage
chunkguard [options]Options
| Option | Description | Default |
|---|---|---|
| --base <branch> | Base branch to compare against | main |
| --dist <path> | Build output directory | dist |
| --max-increase <kb> | Maximum allowed size increase (in KB) | none |
📊 Example
chunkguard --base main --max-increase 50Output:
🛡 ChunkGuard Report
Base: 210.45 KB
Current: 238.12 KB
Diff: +27.67 KBIf the threshold is exceeded:
❌ Bundle size exceeded threshold.Exit code: 1 (CI fails)
📐 How Size Is Calculated
ChunkGuard:
- Builds the base branch
- Builds the current branch
- Scans the
distfolder - Finds all
.jsfiles - Calculates gzip-compressed size
- Compares totals
This approximates real browser transfer size.
⚠️ Requirements
- Must be run inside a Git repository
- Repository must have at least one commit
- Base branch must exist
- Project must have a working
npm run buildscript - Build output must exist in the specified
distfolder
📄 License
MIT
