diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 34032ad4..fb606239 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -55,6 +55,34 @@ export default defineConfig(({ command }) => ({ optimizeDeps: { include: ['avr8js', 'rp2040js', '@wokwi/elements', 'littlefs'], }, + build: { + // Phase 1d #4 — split heavy long-lived chunks so cache-hits stay + // meaningful and the cold-load entry stays small. The previous + // bundle landed the whole app + Monaco + every MCU sim in one + // index chunk (>23 MB). Manual chunks below collapse it into + // cacheable groups that match the user's actual flow (editor + // load, run simulator, edit code in Monaco). + rollupOptions: { + output: { + manualChunks: { + // ngspice WASM client — only loaded when the user opens + // a circuit with electrical components. + 'spice-wasm': [ + './src/simulation/spice/adapters/NgSpiceWorkerAdapter.ts', + './src/simulation/spice/wasm/NgSpiceInteractive.ts', + ], + // MCU emulators — bulky, infrequent updates. + 'mcu-emulators': ['avr8js', 'rp2040js'], + // Wokwi visual elements — large but cacheable; only loaded + // once per session. + 'wokwi-elements': ['@wokwi/elements'], + // React vendor — stable across deploys, near-permanent cache. + 'react-vendor': ['react', 'react-dom', 'react-router-dom'], + }, + }, + }, + chunkSizeWarningLimit: 8000, + }, test: { globals: true, environment: 'node',