-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
117 lines (115 loc) · 3.48 KB
/
Copy pathvite.config.ts
File metadata and controls
117 lines (115 loc) · 3.48 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
109
110
111
112
113
114
115
116
117
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import compression from 'vite-plugin-compression';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, '.', '');
const isProd = mode === 'production';
return {
server: {
port: 3000,
host: '0.0.0.0',
},
plugins: [
react({
// Use automatic JSX runtime for smaller bundle
jsxRuntime: 'automatic',
}),
// 🚀 Precompress assets for instant serving on Cloudflare/Vercel
isProd && compression({
algorithm: 'gzip',
ext: '.gz',
threshold: 1024, // Only compress files > 1KB
}),
isProd && compression({
algorithm: 'brotliCompress',
ext: '.br',
threshold: 1024,
}),
].filter(Boolean),
define: {
'process.env.API_KEY': JSON.stringify(env.GEMINI_API_KEY),
'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY),
// Remove dev-only code in production
'process.env.NODE_ENV': JSON.stringify(mode),
},
resolve: {
alias: {
'@': path.resolve(__dirname, '.'),
}
},
// 🚀 2025 Performance Optimizations
build: {
// Target modern browsers for smaller bundles
target: 'esnext',
// Enable minification with terser for best compression
minify: 'terser',
terserOptions: {
compress: {
drop_console: isProd,
drop_debugger: isProd,
pure_funcs: isProd ? ['console.log', 'console.info'] : [],
passes: 3,
},
mangle: {
safari10: true,
},
format: {
comments: false,
},
},
// CSS code splitting for better caching
cssCodeSplit: true,
// Generate source maps only in dev
sourcemap: !isProd,
// Aggressive chunk size warnings
chunkSizeWarningLimit: 200,
// Rollup optimizations
rollupOptions: {
output: {
// Optimize chunk naming for better caching
chunkFileNames: isProd
? 'assets/[name]-[hash:8].js'
: 'assets/[name].js',
entryFileNames: isProd
? 'assets/[name]-[hash:8].js'
: 'assets/[name].js',
assetFileNames: isProd
? 'assets/[name]-[hash:8].[ext]'
: 'assets/[name].[ext]',
// Advanced manual chunking strategy
// Use object-based chunks to ensure proper loading order
manualChunks: {
// React core + recharts together to avoid forwardRef issue
'vendor-react': ['react', 'react-dom', 'recharts'],
// React Router - separate chunk
'vendor-router': ['react-router-dom'],
// Math rendering (KaTeX)
'vendor-math': ['katex'],
// Lucide icons
'vendor-icons': ['lucide-react'],
},
},
// Tree shake aggressively
treeshake: {
moduleSideEffects: 'no-external',
propertyReadSideEffects: false,
tryCatchDeoptimization: false,
},
},
// Report compressed size
reportCompressedSize: true,
},
// Optimize dependencies
optimizeDeps: {
include: ['react', 'react-dom', 'react-router-dom', 'recharts'],
},
// Enable experimental features for better performance
esbuild: {
// Remove legal comments
legalComments: 'none',
// Use modern syntax
target: 'esnext',
},
};
});