Skip to content

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 ​

FieldDefaultDescription
namebudget-Stable diagnostic name
limitRequiredMaximum bytes; nonnegative safe integer
scope"file"file limits each file; total sums all matched files
mode"raw"raw / gzip / brotli
filterExclude .map/.gz/.brRegExp or (fileName, type) => boolean
requireMatchfalseFail 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 ​

InputTypeRequired / defaultDescription
optionsBundleBudgetPluginOptionsRequiredBudget rules and overrun behavior.

Returns ​

ValueTypeDescription
pluginPluginBundle-budget plugin for Vite plugins.