@shiftescape/astro-bundle-budget
Build-time JS/CSS budget enforcement for Astro. Inspect every asset, set per-file and per-page thresholds, and fail CI automatically when you go over.
features
Zero runtime cost — the entire audit happens at build time.
Every JS and CSS file printed with its exact size after every
astro build.
Target individual files or groups with minimatch glob patterns. First matching rule wins.
Measure the total JS or CSS payload each generated HTML page references across all its assets.
Set budgets against gzip or brotli — the wire size that actually matters to your users.
Exits with code 1 on violation. Works with any CI pipeline.
Disable with
failOnExceed: false.
Write a machine-readable report to diff bundle growth between deploys and track trends over time.
configuration
Add the integration with no options for a free asset table. Add rules when you're ready to enforce.
import { defineConfig } from 'astro/config' import bundleBudget from '@shiftescape/astro-bundle-budget' export default defineConfig({ integrations: [ bundleBudget({ // per-file rules — first matching glob wins budgets: [ { path: 'assets/vendor-*.js', budget: '50 kB' }, { path: '**/*.js', budget: '100 kB' }, { path: '**/*.css', budget: '20 kB' }, ], // per-page payload limits pageBudgets: [ { type: 'js', budget: '150 kB' }, { type: 'total', budget: '200 kB', compression: 'gzip' }, ], }), ], })
| Option | Type | Default | Description |
|---|---|---|---|
| budgets | BudgetRule[] | [] | Per-file glob rules. Each rule sets a max size for matching assets. |
| pageBudgets | PageBudget[] | [] | Per-page payload limits — total JS, CSS, or combined across a single HTML page. |
| failOnExceed | boolean | true | Exit 1 when a budget is exceeded. Set to false to warn but never fail. |
| compression | 'none' | 'gzip' | 'brotli' | 'none' | Measure compressed size per rule. Applies to both file and page budgets. |
| report | boolean | false | Write a JSON report to outDir for CI diffing and build trend tracking. |
| reportPath | string | 'bundle-budget-report.json' | Filename for the JSON report, relative to outDir. |
| verbose | boolean | false | Show every asset and per-page breakdown in the build output. |
install
Add the integration — an asset table appears in every build output immediately.
import bundleBudget from '@shiftescape/astro-bundle-budget' export default defineConfig({ integrations: [bundleBudget()] // asset table in every build })