-
Notifications
You must be signed in to change notification settings - Fork 212
/
vite.config.ts
58 lines (52 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
import type { ConfigEnv } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import { convertEnv, getRootPath, getSrcPath } from './build/utils'
import { viteDefine } from './build/config'
import { setupVitePlugins } from './build/plugins'
export default defineConfig((configEnv: ConfigEnv) => {
const srcPath = getSrcPath()
const rootPath = getRootPath()
const isBuild = configEnv.command === 'build'
const viteEnv = convertEnv(loadEnv(configEnv.mode, process.cwd()))
// vercel配置 修改vercel.json
// const fs = require('fs')
// // 读取JSON文件内容
// const jsonData = JSON.parse(fs.readFileSync('vercel.json'))
// jsonData.rewrites[jsonData.rewrites.length - 1].destination = `${viteEnv.VITE_BASE_URL}/$1`
// // 写入修改后的JSON数据到本地文件中
// fs.writeFileSync('vercel.json', JSON.stringify(jsonData))
// // eslint-disable-next-line no-console
const { VITE_PORT, VITE_PUBLIC_PATH } = viteEnv
return {
base: VITE_PUBLIC_PATH,
resolve: {
alias: {
'~': rootPath,
'@': srcPath,
},
},
define: viteDefine,
plugins: setupVitePlugins(viteEnv, isBuild),
server: {
host: '0.0.0.0',
port: VITE_PORT,
open: false,
proxy: {
'/api': {
target: viteEnv.VITE_BASE_URL,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''), // 不可以省略rewrite
// rewrite: path => path.replace('/api/', '/'),
},
},
},
build: {
reportCompressedSize: false,
sourcemap: false,
chunkSizeWarningLimit: 1024, // chunk 大小警告的限制(单位kb)
commonjsOptions: {
ignoreTryCatch: false,
},
},
}
})