mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-06 16:26:04 +08:00
build(projects): vite.config代码优化
This commit is contained in:
23
build/config/proxy.ts
Normal file
23
build/config/proxy.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { ProxyOptions } from 'vite';
|
||||
import { getEnvConfig } from '../../.env-config';
|
||||
|
||||
/**
|
||||
* 设置网络代理
|
||||
* @param viteEnv
|
||||
*/
|
||||
export function createViteProxy(viteEnv: ImportMetaEnv) {
|
||||
const isOpenProxy = viteEnv.VITE_HTTP_PROXY === 'true';
|
||||
if (!isOpenProxy) return undefined;
|
||||
|
||||
const { http } = getEnvConfig(viteEnv);
|
||||
|
||||
const proxy: Record<string, string | ProxyOptions> = {
|
||||
[http.proxy]: {
|
||||
target: http.url,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(new RegExp(`^${http.proxy}`), ''),
|
||||
},
|
||||
};
|
||||
|
||||
return proxy;
|
||||
}
|
||||
Reference in New Issue
Block a user