-
Notifications
You must be signed in to change notification settings - Fork 28
/
vite.config.ts
72 lines (62 loc) · 1.76 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
60
61
62
63
64
65
66
67
68
69
70
71
72
import type { ConfigEnv, UserConfig } from 'vite'
import { loadEnv } from 'vite'
import { createProxy } from './build/vite/proxy'
import { createVitePlugins } from './build/vite/plugin'
import { wrapperEnv } from './build/utils'
// need install plugin @typings/node
import { resolve } from 'path'
function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir)
}
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd()
const env = loadEnv(mode, root)
// this function can be converted to different typings
const viteEnv = wrapperEnv(env)
const { VITE_PORT, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv
const isBuild = command === 'build'
return {
base: './',
server: {
// Listening on all local ips
host: true,
open: true,
port: VITE_PORT,
// Load proxy configuration from .env
proxy: createProxy(VITE_PROXY)
},
// the project uses lots of vite plugins, so they are extracted and managed separately
plugins: createVitePlugins(isBuild),
build: {
target: 'es2015',
cssTarget: 'chrome86',
minify: 'terser',
terserOptions: {
compress: {
keep_infinity: true,
// used to delete console and debugger in production environment
drop_console: VITE_DROP_CONSOLE
}
},
chunkSizeWarningLimit: 2000
},
css: {
preprocessorOptions: {
less: {
charset: false,
additionalData: `@import "${resolve('src/design/variable/index.less')}";`,
javascriptEnabled: true
}
}
},
resolve: {
alias: [
{
find: /@\//,
replacement: pathResolve('src') + '/'
}
]
}
}
}