-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
108 lines (100 loc) · 2.81 KB
/
vite.config.ts
File metadata and controls
108 lines (100 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { cpSync, existsSync } from 'node:fs';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import type { Plugin } from 'vite';
const copyQuizBanksPlugin = (): Plugin => {
let quizBanksSourceDir = '';
let quizBanksOutputDir = '';
return {
name: 'copy-quiz-banks',
apply: 'build',
configResolved(config) {
quizBanksSourceDir = resolve(config.root, 'quiz-banks');
quizBanksOutputDir = resolve(config.root, config.build.outDir, 'quiz-banks');
},
closeBundle() {
if (!existsSync(quizBanksSourceDir)) {
return;
}
cpSync(quizBanksSourceDir, quizBanksOutputDir, { recursive: true });
},
};
};
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
copyQuizBanksPlugin(),
// Bundle analyzer - generates stats.html
visualizer({
open: false,
filename: 'dist/stats.html',
gzipSize: true,
brotliSize: true,
}) as Plugin,
],
// @ts-expect-error - Vitest config
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.ts',
css: true,
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'src/test/',
'**/*.d.ts',
'**/*.config.*',
'**/mockData',
'**/types',
],
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
if (id.includes('three')) {
return 'vendor-three';
}
if (id.includes('monaco-editor')) {
return 'vendor-monaco';
}
if (id.includes('@xyflow')) {
return 'vendor-xyflow';
}
// Let Rollup group the rest of node_modules automatically.
// The previous manual vendor splitting created circular chunk dependencies
// that broke the production preview runtime.
return undefined;
}
if (id.includes('/src/components/models3d/python/')) {
return 'python-3d';
}
if (id.includes('/src/components/models3d/')) {
return 'models-3d';
}
return undefined;
},
},
},
// Optimize chunk size
chunkSizeWarningLimit: 500, // Warn for chunks > 500KB
target: 'esnext',
minify: 'esbuild',
// Enable source maps for production debugging
sourcemap: false,
},
// Optimize dependencies
optimizeDeps: {
include: ['react', 'react-dom', 'react-router-dom', 'lucide-react'],
exclude: ['three'], // Three.js has its own optimization
},
});