diff --git a/vite.config.ts b/vite.config.ts index 1b8edb37..6125d39e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -19,6 +19,13 @@ const pdfjsAssets = () => ({ // so hashed chunks from previous builds would otherwise accumulate // forever and leak into Docker images via the build context. Remove // any *-.js/.css/.mjs(.map) that this build did not produce. +// +// The produced.size === 0 guard is load-bearing: this config also drives +// `vp test`, and vitest runs closeBundle with generateBundle never having +// fired — an empty produced set means "not a build run", and sweeping +// then deleted every live chunk (the 2026-10-21 incident where +// `npm run test` gutted web/static down to the three entry files and +// every page 404'd its imports). const cleanStaleChunks = () => { const produced = new Set(); return { @@ -27,6 +34,7 @@ const cleanStaleChunks = () => { for (const fileName of Object.keys(bundle)) produced.add(fileName); }, closeBundle() { + if (produced.size === 0) return; const outDir = "web/static"; const chunkRe = /-[A-Za-z0-9_-]{8}\.(js|css|mjs)(\.map)?$/; for (const f of readdirSync(outDir)) {