refactor: 简化proxy配置

This commit is contained in:
zclzone
2023-06-21 21:53:33 +08:00
parent a610c1c6d0
commit 0247f3ebfa
8 changed files with 43 additions and 60 deletions

View File

@@ -1,9 +1,8 @@
import { defineConfig, loadEnv } from 'vite'
import { convertEnv, getSrcPath, getRootPath } from './build/utils'
import { createViteProxy, viteDefine } from './build/config'
import { createVitePlugins } from './build/plugin'
import { OUTPUT_DIR } from './build/constant'
import { OUTPUT_DIR, PROXY_CONFIG } from './build/constant'
export default defineConfig(({ command, mode }) => {
const srcPath = getSrcPath()
@@ -12,7 +11,7 @@ export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd())
const viteEnv = convertEnv(env)
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_USE_PROXY, VITE_PROXY_TYPE } = viteEnv
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_USE_PROXY, VITE_BASE_API } = viteEnv
return {
base: VITE_PUBLIC_PATH || '/',
@@ -22,17 +21,21 @@ export default defineConfig(({ command, mode }) => {
'@': srcPath,
},
},
define: viteDefine,
plugins: createVitePlugins(viteEnv, isBuild),
server: {
host: '0.0.0.0',
port: VITE_PORT,
open: false,
proxy: createViteProxy(VITE_USE_PROXY, VITE_PROXY_TYPE),
proxy: VITE_USE_PROXY
? {
[VITE_BASE_API]: PROXY_CONFIG[VITE_BASE_API],
'/api/v2': PROXY_CONFIG['/api/v2'],
}
: undefined,
},
build: {
target: 'es2015',
outDir: OUTPUT_DIR,
outDir: OUTPUT_DIR || 'dist',
reportCompressedSize: false, // 启用/禁用 gzip 压缩大小报告
chunkSizeWarningLimit: 1024, // chunk 大小警告的限制单位kb
},