remora/web/tools/check-bundle.mjs

24 lines
682 B
JavaScript
Raw Normal View History

import { readdirSync, statSync } from 'node:fs'
import { extname, resolve } from 'node:path'
const assets = resolve('dist/assets')
const limits = new Map([
['.js', 256 * 1024],
['.css', 64 * 1024],
])
const totals = new Map()
for (const entry of readdirSync(assets)) {
const extension = extname(entry)
if (!limits.has(extension)) continue
totals.set(
extension,
(totals.get(extension) ?? 0) + statSync(resolve(assets, entry)).size,
)
}
for (const [extension, limit] of limits) {
const total = totals.get(extension) ?? 0
if (total > limit)
throw new Error(
`${extension.slice(1).toUpperCase()} bundle is ${total} bytes; limit is ${limit}`,
)
}