refactor(projects): 细节优化

This commit is contained in:
Soybean
2022-04-27 22:27:46 +08:00
parent e899914426
commit c275f2632c
10 changed files with 87 additions and 91 deletions

View File

@ -1,21 +1,18 @@
import type { ProxyOptions } from 'vite';
import { getEnvConfig } from '../../.env-config';
/**
* 设置网络代理
* @param viteEnv - vite环境描述
* @param isOpenProxy - 是否开启代理
* @param envConfig - env环境配置
*/
export function createViteProxy(viteEnv: ImportMetaEnv) {
const isOpenProxy = viteEnv.VITE_HTTP_PROXY === 'true';
export function createViteProxy(isOpenProxy: boolean, envConfig: EnvConfig) {
if (!isOpenProxy) return undefined;
const { http } = getEnvConfig(viteEnv);
const proxy: Record<string, string | ProxyOptions> = {
[http.proxy]: {
target: http.url,
[envConfig.proxy]: {
target: envConfig.url,
changeOrigin: true,
rewrite: path => path.replace(new RegExp(`^${http.proxy}`), '')
rewrite: path => path.replace(new RegExp(`^${envConfig.proxy}`), '')
}
};