perf: 将baseURL和全局环境代理删除,可直接在vite.config.ts编写,即方便又支持多个代理地址

This commit is contained in:
xiaoxian521
2022-11-10 11:47:07 +08:00
parent 731e9b2f57
commit 2bb433c3cd
14 changed files with 15 additions and 57 deletions

View File

@@ -1,7 +1,7 @@
import dayjs from "dayjs";
import { resolve } from "path";
import pkg from "./package.json";
import { warpperEnv, regExps } from "./build";
import { warpperEnv } from "./build";
import { getPluginsList } from "./build/plugins";
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
@@ -31,9 +31,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
VITE_PORT,
VITE_LEGACY,
VITE_COMPRESSION,
VITE_PUBLIC_PATH,
VITE_PROXY_DOMAIN,
VITE_PROXY_DOMAIN_REAL
VITE_PUBLIC_PATH
} = warpperEnv(loadEnv(mode, root));
return {
base: VITE_PUBLIC_PATH,
@@ -48,18 +46,8 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
// 端口号
port: VITE_PORT,
host: "0.0.0.0",
// 本地跨域代理
proxy:
VITE_PROXY_DOMAIN_REAL.length > 0
? {
[VITE_PROXY_DOMAIN]: {
target: VITE_PROXY_DOMAIN_REAL,
// ws: true,
changeOrigin: true,
rewrite: (path: string) => regExps(path, VITE_PROXY_DOMAIN)
}
}
: null
// 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {}
},
plugins: getPluginsList(command, VITE_LEGACY, VITE_CDN, VITE_COMPRESSION),
optimizeDeps: {