-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathvite.config.ts
More file actions
73 lines (71 loc) · 2.03 KB
/
Copy pathvite.config.ts
File metadata and controls
73 lines (71 loc) · 2.03 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
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, '.', '');
return {
server: {
port: 3000,
host: '0.0.0.0',
open: true,
},
plugins: [
react(),
],
// define: {
// // 移除API密钥暴露到前端的配置
// // API密钥应该只在后端使用
// },
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './components'),
'@services': path.resolve(__dirname, './services'),
'@utils': path.resolve(__dirname, './utils'),
'@types': path.resolve(__dirname, './types'),
}
},
build: {
outDir: 'dist',
sourcemap: mode === 'development',
minify: 'terser',
terserOptions: {
compress: {
drop_console: mode === 'production',
drop_debugger: mode === 'production',
},
},
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules/react/') || id.includes('node_modules/react-dom/')) {
return 'vendor';
}
if (id.includes('node_modules/lucide-react/')) {
return 'ui';
}
if (id.includes('node_modules/@dnd-kit/')) {
return 'dnd';
}
},
chunkFileNames: 'assets/[name]-[hash].js',
entryFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]',
},
},
// 减小 chunk 大小限制
chunkSizeWarningLimit: 500,
// 启用 Tree Shaking
target: 'esnext',
},
optimizeDeps: {
include: ['react', 'react-dom', 'lucide-react'],
},
css: {
devSourcemap: true,
},
preview: {
port: 4173,
},
};
});