18 lines
660 B
JavaScript
18 lines
660 B
JavaScript
import { readdir, stat } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import assert from "node:assert/strict";
|
|
const assets = new URL("../dist/assets/", import.meta.url);
|
|
const files = (await readdir(assets)).filter((file) => file.endsWith(".js"));
|
|
assert(files.length > 0, "No built JavaScript assets were found.");
|
|
for (const file of files) {
|
|
const size = (await stat(join(fileURLToPath(assets), file))).size;
|
|
assert(
|
|
size < 500000,
|
|
`${file} exceeds the 500 kB chunk budget (${size} bytes).`,
|
|
);
|
|
}
|
|
console.log(
|
|
`Build budget passed: ${files.length} JavaScript chunks below 500 kB.`,
|
|
);
|