-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathvite.config.ts
More file actions
58 lines (57 loc) · 1.6 KB
/
vite.config.ts
File metadata and controls
58 lines (57 loc) · 1.6 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
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import viteCompression from 'vite-plugin-compression';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, '.', '');
return {
base: mode === 'production' ? '/FreeTool/' : '/',
server: {
port: 3000,
host: '0.0.0.0',
},
plugins: [
react(),
// Gzip 压缩
viteCompression({
algorithm: 'gzip',
ext: '.gz',
threshold: 10240, // 仅压缩大于 10KB 的文件
deleteOriginFile: false,
}),
// Brotli 压缩(更高压缩率)
viteCompression({
algorithm: 'brotliCompress',
ext: '.br',
threshold: 10240,
deleteOriginFile: false,
}),
],
define: {
'process.env.API_KEY': JSON.stringify(env.GEMINI_API_KEY),
'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY)
},
resolve: {
alias: {
'@': path.resolve(__dirname, '.'),
}
},
build: {
// 代码分割优化
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom'],
'pdf-vendor': ['pdfjs-dist', 'pptxgenjs'],
},
},
},
// 启用 CSS 代码分割
cssCodeSplit: true,
// 生成 sourcemap 仅在开发环境
sourcemap: mode !== 'production',
// 优化分块大小警告阈值
chunkSizeWarningLimit: 1000,
},
};
});