Build: landing/learn shed eager Monaco+Vega; post-build gate + immutable asset caching

This commit is contained in:
2026-07-02 22:34:24 +03:00
parent fb4b42a1a7
commit 552900dac5
11 changed files with 170 additions and 77 deletions
+32 -3
View File
@@ -44,9 +44,38 @@ export default defineConfig({
// Split the heavy vendors so the chunk graph stays legible and the PWA
// can precache/update them independently of app code. Monaco and the
// Vega stack are each multi-MB; isolating them keeps app rebuilds small.
manualChunks: {
monaco: ['monaco-editor'],
vega: ['vega', 'vega-lite', 'vega-embed'],
//
// Function form with explicit homes for every module the light and
// heavy graphs *share* — Rollup merges small shared modules into their
// biggest importer, which is how the landing's eager JS twice gained a
// static edge into a multi-MB vendor chunk:
// - Vite's dynamic-import preload helper (a virtual module used by
// every chunk that calls `import()`, monaco included) was absorbed
// into the monaco chunk, chaining the landing's lazy chart embed to
// all of Monaco. It gets its own micro-chunk.
// - vega-themes (preset config data), vega-expression (+ its dep
// vega-util), and json-stringify-pretty-compact (used by core's
// json-format) are imported both by core modules the landing/learn
// entries reach and by vega/vega-embed internals; unassigned, they
// were absorbed into the vega chunk. They get a small shared
// 'vendor-light' chunk — the heavy chunk importing the light one is
// fine, the reverse is not. vega-scale stays unassigned: after the
// scheme-colors.ts split, only app code and vega internals reach it.
// `scripts/check-light-entries.mjs` asserts the invariant (no
// vendor-monaco/vendor-vega reference in the landing/learn HTML) after
// every build.
manualChunks: (id: string) => {
if (id.includes('vite/preload-helper')) return 'preload-helper';
if (!id.includes('node_modules')) return undefined;
if (id.includes('node_modules/monaco-editor/')) return 'vendor-monaco';
if (
/node_modules\/(vega-themes|vega-expression|vega-util|json-stringify-pretty-compact)\//.test(
id,
)
)
return 'vendor-light';
if (/node_modules\/(vega|vega-lite|vega-embed)\//.test(id)) return 'vendor-vega';
return undefined;
},
},
},