19 lines
817 B
JavaScript
19 lines
817 B
JavaScript
import { readdirSync, statSync } from 'node:fs'
|
|
import { 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 detailChunk = files.find(file => /^_virtual_content-details-[^/]+\.js$/.test(file))
|
|
const maxInitialBytes = 700 * 1024
|
|
|
|
if (!entry) throw new Error('Kein initialer JavaScript-Entry-Chunk gefunden.')
|
|
if (!detailChunk) throw new Error('Kein separater Content-Detail-Chunk gefunden.')
|
|
|
|
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-Chunk=${detailChunk}`)
|