nova-admin/build/proxy.ts
2024-03-01 17:37:21 +08:00

18 lines
450 B
TypeScript

import type { ProxyOptions } from 'vite'
/**
* @description: 生成vite代理字段
* @param {*} envConfig - 环境变量配置
*/
export function createViteProxy(envConfig: ServiceEnvConfig) {
const proxy: Record<string, string | ProxyOptions> = {
[envConfig.urlPattern]: {
target: envConfig.url,
changeOrigin: true,
rewrite: path => path.replace(new RegExp(`^${envConfig.urlPattern}`), ''),
},
}
return proxy
}