forked from XPoet/picx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
70 lines (65 loc) · 1.85 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
import { loadEnv } from 'vite'
import { resolve } from 'path'
import type { UserConfig, ConfigEnv } from 'vite'
import createVitePlugins from './src/plugins'
import wrapperEnv from './src/common/utils/env'
function pathResolve(dir: string) {
return resolve(__dirname, '.', dir)
}
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd()
const env = loadEnv(mode, root)
const isBuild = command === 'build'
// loadEnv 中返回的是 string 类型的(即使是 boolean),下面的方法可以返回正确的类型
const viteEnv = wrapperEnv(env)
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_OPEN_BROWSER, VITE_CORS } = viteEnv
return {
plugins: createVitePlugins(viteEnv, isBuild),
resolve: {
alias: {
'@': pathResolve('src') // 设置 @ 指向 src
}
},
base: VITE_PUBLIC_PATH, // 设置打包路径
server: {
port: VITE_PORT,
open: VITE_OPEN_BROWSER,
cors: VITE_CORS
/**
* 设置代理(解决前端跨域问题)
* /api -> https://xxx.xxx.com
* ^/API -> /
* /api/aa/bb -> https://xxx.xxx.com/aa/bb
* /api/API/aa/bb -> https://xxx.xxx.com/aa/bb
*/
// proxy: {
// '/api': {
// target: 'https://xxx.xxx.com',
// changeOrigin: true,
// secure: true,
// rewrite: (path) => path.replace('^/API', '/')
// }
// }
},
optimizeDeps: {
exclude: ['@yireen/squoosh-browser']
},
css: {
postcss: {
plugins: [
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: (atRule) => {
if (atRule.name === 'charset') {
atRule.remove()
}
}
}
}
]
}
}
}
}