-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
59 lines (49 loc) · 1.56 KB
/
vite.config.ts
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
import { ConfigEnv, defineConfig, loadEnv, UserConfig } from 'vite'
import { resolve } from 'path'
import { wrapperEnv } from './build/utils'
import { createProxy } from './build/vite/proxy'
import { OUTPUT_DIR } from './build/constant'
import { configVitePlugins } from './build/vite/plugins/index'
function pathResolve (dir: string) {
return resolve(process.cwd(), '.', dir)
}
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
const isBuild = command === 'build'
const root = process.cwd()
const env = loadEnv(mode, root)
// loadEnv 读取的布尔类型都为字符串,需要通过该方法转为相应类型
const viteEnv = wrapperEnv(env)
const { VITE_PROT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONFIG } = viteEnv
return {
root,
base: VITE_PUBLIC_PATH,
resolve: {
alias: [
// /@/xxx => src/xxx
{ find: /\/@\//, replacement: pathResolve('src') + '/' },
// /$/xxx => src/xxx
{ find: /\/$\//, replacement: pathResolve('build') + '/' },
]
},
server: {
port: VITE_PROT,
// 从 .env.development 加载代理配置
proxy: createProxy(VITE_PROXY)
},
build: {
target: 'es2015',
outDir: OUTPUT_DIR,
terserOptions: {
compress: {
keep_infinity: true,
drop_console: VITE_DROP_CONFIG
}
},
// 关闭 brotliSize 的显示可减少打包时间
brotliSize: false,
chunkSizeWarningLimit: 1500
},
plugins: configVitePlugins(viteEnv, isBuild)
}
})