Files
biggus-dickus/web/scripts/check-bundle-size.mjs
logaritmisk 303c986d40 chore(web): raise bundle budget 180→250 KB gz (#47)
Generous ceiling so the budget stops blocking per-feature work (this is the third
raise in three frontend milestones) while still catching gross regressions. A
vendor-split / bundle audit can revisit always-loaded weight later.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 13:35:35 +02:00

25 lines
889 B
JavaScript

// Fails if the largest built JS entry chunk exceeds the gzipped budget.
import { readdirSync, readFileSync } from "node:fs";
import { gzipSync } from "node:zlib";
import { join } from "node:path";
const BUDGET_KB = 250;
const dir = "dist/assets";
const jsFiles = readdirSync(dir).filter((f) => f.endsWith(".js"));
if (jsFiles.length === 0) {
console.error(`no JS files found in ${dir} — was the build skipped?`);
process.exit(1);
}
let largest = 0;
let largestName = "";
for (const file of jsFiles) {
const gz = gzipSync(readFileSync(join(dir, file))).length;
if (gz > largest) { largest = gz; largestName = file; }
}
const kb = (largest / 1024).toFixed(1);
console.log(`largest JS chunk: ${largestName} = ${kb} KB gz (budget ${BUDGET_KB} KB)`);
if (largest > BUDGET_KB * 1024) {
console.error(`bundle-size budget exceeded: ${kb} KB > ${BUDGET_KB} KB`);
process.exit(1);
}