From 84174323437cc392850b5156dc1587d6a4746f4d Mon Sep 17 00:00:00 2001 From: chansee97 Date: Sat, 30 Aug 2025 22:32:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E7=8E=AF=E5=A2=83=E5=90=8D=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/autoProxy.ts | 13 ++++--------- build/plugins.ts | 1 - 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/build/autoProxy.ts b/build/autoProxy.ts index 7105246..044dd1a 100644 --- a/build/autoProxy.ts +++ b/build/autoProxy.ts @@ -34,8 +34,6 @@ export interface ServiceProxyPluginOptions { serviceConfig: FullServiceConfig /** 代理路径前缀(可选,默认为 'proxy-') */ proxyPrefix?: string - /** 开发环境名称(可选,默认为 'development') */ - devEnvName?: ServiceEnvType /** 是否启用代理配置 */ enableProxy?: boolean /** 环境变量名(可选,默认为 '__URL_MAP__') */ @@ -47,7 +45,6 @@ export interface ServiceProxyPluginOptions { export default function createServiceProxyPlugin(options: ServiceProxyPluginOptions) { const { serviceConfig, - devEnvName = 'development', proxyPrefix = 'proxy-', enableProxy = true, envName = '__URL_MAP__', @@ -66,10 +63,8 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti } if (!enableProxy || !isDev) { - // 在非开发环境下,根据构建模式选择正确的环境配置 - const targetEnv = isDev ? devEnvName : mode const rawMapping: ProxyMapping = {} - const envConfig = serviceConfig[targetEnv] + const envConfig = serviceConfig[mode] if (envConfig) { Object.entries(envConfig).forEach(([serviceName, serviceUrl]) => { @@ -81,7 +76,7 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti console.warn(`[auto-proxy] 已加载 ${Object.keys(envConfig).length} 个服务地址`) } else { - console.warn(`[auto-proxy] 未找到环境 "${targetEnv}" 的配置`) + console.warn(`[auto-proxy] 未找到环境 "${mode}" 的配置`) } config.define[envName] = JSON.stringify(rawMapping) @@ -93,9 +88,9 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti return } - console.warn(`[auto-proxy] 已加载${devEnvName}模式 ${Object.keys(serviceConfig[devEnvName]).length} 个服务地址`) + console.warn(`[auto-proxy] 已加载${mode}模式 ${Object.keys(serviceConfig[mode]).length} 个服务地址`) - const { proxyConfig, proxyMapping } = generateProxyFromServiceConfig(serviceConfig, devEnvName, proxyPrefix) + const { proxyConfig, proxyMapping } = generateProxyFromServiceConfig(serviceConfig, mode, proxyPrefix) Object.entries(proxyMapping).forEach(([serviceName, proxyItem]) => { console.warn(`[auto-proxy] 服务: ${serviceName} | 代理地址: ${proxyItem.path} | 实际地址: ${proxyItem.rawPath}`) diff --git a/build/plugins.ts b/build/plugins.ts index c82ea60..df6a694 100644 --- a/build/plugins.ts +++ b/build/plugins.ts @@ -83,7 +83,6 @@ export function createVitePlugins(env: ImportMetaEnv) { AutoProxy({ enableProxy: env.VITE_HTTP_PROXY === 'Y', serviceConfig, - devEnvName: 'dev', dts: 'src/typings/auto-proxy.d.ts', }), ]