bundleBudget(options)
Enforces final-output budgets that can fail CI, extending Vite's chunk-only warnings to CSS, totals, and compressed sizes.
ts
bundleBudget({
budgets: [
{ name: "单个入口 JS", filter: /\.js$/, limit: 250 * 1024, requireMatch: true },
{ name: "CSS 总量", filter: /\.css$/, limit: 50 * 1024, mode: "gzip", scope: "total" },
],
onExceed: "error",
});BundleBudgetRule Rule
| Field | Default | Description |
|---|---|---|
name | budget- | Stable diagnostic name |
limit | Required | Maximum bytes; nonnegative safe integer |
scope | "file" | file limits each file; total sums all matched files |
mode | "raw" | raw / gzip / brotli |
filter | Exclude .map/.gz/.br | RegExp or (fileName, type) => boolean |
requireMatch | false | Fail when no assets match, preventing renames from silently disabling budgets |
onExceed defaults to error. Warn is for temporary observation, not CI gates. gzip/Brotli sizes use actual Node-native compression, not estimates.
bundleBudget Budget
Adds enforceable output-size budgets to Vite builds.
Unlike native chunk warnings, checks arbitrary outputs, aggregates files, measures actual compressed sizes, and can fail CI on overruns. Runs only in production builds.
Signature
ts
export function bundleBudget(options: BundleBudgetPluginOptions): Plugin;Example
ts
import { bundleBudget } from "fast-vite-plugins";
const plugin = bundleBudget({ budgets: [{ name: "entry", filter: /\.js$/, limit: 250 * 1024 }] });
export default { plugins: [plugin] };Input
| Input | Type | Required / default | Description |
|---|---|---|---|
options | BundleBudgetPluginOptions | Required | Budget rules and overrun behavior. |
Returns
| Value | Type | Description |
|---|---|---|
plugin | Plugin | Bundle-budget plugin for Vite plugins. |
