28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
import { readdirSync, statSync } from 'node:fs'
|
|
import { basename, join } from 'node:path'
|
|
|
|
const assetsDir = join(process.cwd(), 'dist', 'assets')
|
|
const files = readdirSync(assetsDir)
|
|
const entry = files.find(file => /^index-[^/]+\.js$/.test(file))
|
|
const detailSlugs = ['posts', 'kniepunkt'].flatMap(type =>
|
|
readdirSync(join(process.cwd(), 'content', type))
|
|
.filter(file => file.endsWith('.md'))
|
|
.map(file => basename(file, '.md')),
|
|
)
|
|
const missingDetailChunks = detailSlugs.filter(
|
|
slug => !files.some(file => file.startsWith(`${slug}-`) && file.endsWith('.js')),
|
|
)
|
|
const maxInitialBytes = 400 * 1024
|
|
|
|
if (!entry) throw new Error('Kein initialer JavaScript-Entry-Chunk gefunden.')
|
|
if (missingDetailChunks.length > 0) {
|
|
throw new Error(`Fehlende Content-Detail-Chunks: ${missingDetailChunks.join(', ')}`)
|
|
}
|
|
|
|
const entryBytes = statSync(join(assetsDir, entry)).size
|
|
if (entryBytes > maxInitialBytes) {
|
|
throw new Error(`Initialer JS-Chunk ist zu groß: ${entryBytes} Bytes (Limit ${maxInitialBytes}).`)
|
|
}
|
|
|
|
console.log(`Bundle-Prüfung: ${entry}=${entryBytes} Bytes, Detail-Chunks=${detailSlugs.length}`)
|