-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
44 lines (43 loc) · 1.21 KB
/
vite.config.ts
File metadata and controls
44 lines (43 loc) · 1.21 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
import * as process from 'node:process'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import { createVitePlugins } from './build/plugins'
import { proxyConfig } from './build/proxy'
import { getMetaEnv } from './src/utils/env'
export default defineConfig(({ mode }) => {
const root = process.cwd()
// 获取并包装 .env 环境变量
const viteEnv = getMetaEnv(loadEnv(mode, root))
return {
root,
base: viteEnv.VITE_PUBLIC_PATH,
plugins: createVitePlugins(viteEnv),
server: {
host: true,
port: viteEnv.VITE_PORT,
proxy: proxyConfig(viteEnv),
},
resolve: {
// 别名
alias: {
'~': fileURLToPath(new URL('./', import.meta.url)),
'@': fileURLToPath(new URL('./src', import.meta.url)),
'#': fileURLToPath(new URL('./types', import.meta.url)),
},
},
build: {
reportCompressedSize: true,
sourcemap: false,
minify: 'terser',
brotliSize: true,
terserOptions: {
compress: {
// 删除所有 console
drop_console: viteEnv.VITE_DELETE_CONSOLE,
// 删除 所有 debugger
drop_debugger: true,
},
},
},
}
})