From 23b50905d8661138142cb40c00bc83f2fb5772e7 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Sat, 11 Oct 2025 19:46:50 +0200 Subject: [PATCH] maplibre chunk in vite.config --- app/vite.config.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/vite.config.ts b/app/vite.config.ts index 5fff90b7..fa2b8910 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -22,10 +22,21 @@ export default defineConfig({ plugins: [react(), tailwindcss(), tsConfigPaths()], build: { sourcemap: true, + modulePreload: { + // Don't preload maplibre chunks - only load when actually needed + resolveDependencies: (_filename, deps) => { + return deps.filter((dep) => !dep.includes('maplibre')) + }, + }, rollupOptions: { output: { manualChunks: (id) => { - if (id.includes('lib/src')) { + // Handle lib source (dev) or dist (prod) + if (id.includes('lib/src') || id.includes('lib/dist')) { + // Separate chunk for MapLibre components + if (id.includes('MapLibre')) { + return 'maplibre-layer' + } return 'utopia-ui' } if (id.includes('node_modules')) { @@ -38,6 +49,10 @@ export default defineConfig({ if (id.includes('leaflet')) { return 'leaflet' } + // Separate chunk for maplibre-gl + if (id.includes('maplibre-gl')) { + return 'maplibre-gl' + } return 'vendor' } },