-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.renderer.config.ts
More file actions
57 lines (55 loc) · 1.49 KB
/
Copy pathvite.renderer.config.ts
File metadata and controls
57 lines (55 loc) · 1.49 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'node:path';
import type { PluginOption } from 'vite';
import { visualizer } from 'rollup-plugin-visualizer';
// https://vitejs.dev/config
export default defineConfig(({ mode }) => {
const isProduction = mode === 'production';
return {
root: 'src/renderer',
plugins: [
react(),
...(isProduction ? [visualizer({ open: true, filename: 'bundle-report.html', gzipSize: true, brotliSize: true })] : [])
] as PluginOption[],
base: './',
build: {
outDir: '../../dist/renderer',
emptyOutDir: true,
rollupOptions: {
input: path.resolve(__dirname, 'src/renderer/index.html'),
external: [],
},
// 只在生产环境中去除 console.log
...(isProduction && {
minify: 'terser',
terserOptions: {
compress: {
// 去除 console.log
drop_console: true,
// 去除 debugger
drop_debugger: true,
// 去除未使用的代码
dead_code: true,
},
mangle: {
// 混淆变量名
toplevel: true,
},
},
}),
},
optimizeDeps: {
include: ['scheduler'],
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
// 定义全局变量,用于代码中的条件编译
define: {
__DEV__: JSON.stringify(!isProduction),
},
};
});