-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathvite.config.ts
58 lines (52 loc) · 1.65 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
import { resolve } from 'path'
import type { ConfigEnv, UserConfig } from 'vite'
import { loadEnv } from 'vite'
import { CHUNK_SIZE_WARNING_LIMIT, OUT_DIR } from './build/constant'
import { wrapperEnv } from './build/utils'
import { vitePlugins } from './build/vite/plugin'
import { createProxy } from './build/vite/proxy'
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd()
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
const env = loadEnv(mode, root)
const isBuild = command === 'build'
const { VITE_PORT, VITE_PROXY, VITE_USE_MOCK, VITE_OPEN } = wrapperEnv(env)
return {
server: {
port: VITE_PORT,
host: '0.0.0.0',
open: VITE_OPEN,
// Load proxy configuration from .env
proxy: createProxy(VITE_PROXY),
hmr: {
overlay: true
}
},
css: {
// user javascriptEnabled
preprocessorOptions: {
less: {
javascriptEnabled: true
}
}
},
plugins: vitePlugins(VITE_USE_MOCK, isBuild),
build: {
outDir: OUT_DIR,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
},
chunkSizeWarningLimit: CHUNK_SIZE_WARNING_LIMIT
},
resolve: {
// set alias
alias: {
'/@/': resolve(__dirname, 'src') + '/'
}
}
}
}