Skip to content

Commit 1f9f3d1

Browse files
fix: enable code splitting to prevent bundle truncation on GitHub Pages
The single 1.6MB bundle was being truncated to 10KB by GitHub Pages. Enabled code splitting to break the bundle into smaller chunks: - vendor-three.js: 640KB (Three.js and related) - vendor.js: 337KB (other vendor libraries) - vendor-react.js: 256KB (React and related) - Various app chunks: <200KB each This resolves the JavaScript syntax error caused by truncated files. Benefits: better caching, faster load times, no truncation issues.
1 parent c1daaa1 commit 1f9f3d1

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

vite.config.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,26 @@ export default defineConfig(({ mode }) => {
244244
rollupOptions: {
245245
external: isProd ? [...PROD_EXTERNAL_PATTERNS] : [],
246246
output: {
247-
// Chunking disabled - all code in single bundle
247+
// Enable chunking to split large bundle into manageable files
248248
chunkFileNames: ASSETS_CHUNK_FILE_PATTERN,
249249
entryFileNames: ASSETS_ENTRY_FILE_PATTERN,
250250
assetFileNames: ASSETS_FILE_PATTERN,
251-
// Inline all dynamic imports into single bundle
252-
inlineDynamicImports: true
251+
// Enable code splitting for better caching and smaller files
252+
manualChunks: (id) => {
253+
// Split large vendor libraries
254+
if (id.includes('node_modules')) {
255+
if (id.includes('react')) {
256+
return 'vendor-react';
257+
}
258+
if (id.includes('three') || id.includes('@react-three')) {
259+
return 'vendor-three';
260+
}
261+
if (id.includes('i18next')) {
262+
return 'vendor-i18n';
263+
}
264+
return 'vendor';
265+
}
266+
}
253267
},
254268

255269
treeshake: disableTreeShaking ? false : (enableDCE ? {

0 commit comments

Comments
 (0)