From 050ab3e7ed7c44c96439c54eeaa7ddafaf8f23b6 Mon Sep 17 00:00:00 2001 From: chansee97 Date: Wed, 20 Aug 2025 17:43:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=AD=A3=E5=BC=8F?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=9C=B0=E5=9D=80=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.prod => .env.production | 0 build/autoProxy.ts | 13 ++++++++++--- netlify.toml | 17 ----------------- package.json | 4 ++-- service.config.ts | 2 +- src/typings/env.d.ts | 2 +- 6 files changed, 14 insertions(+), 24 deletions(-) rename .env.prod => .env.production (100%) delete mode 100644 netlify.toml diff --git a/.env.prod b/.env.production similarity index 100% rename from .env.prod rename to .env.production diff --git a/build/autoProxy.ts b/build/autoProxy.ts index 0d1672a..13d3dfd 100644 --- a/build/autoProxy.ts +++ b/build/autoProxy.ts @@ -56,7 +56,7 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti return { name: 'vite-auto-proxy', - config(config: UserConfig, { command }: { mode: string, command: 'build' | 'serve' }) { + config(config: UserConfig, { mode, command }: { mode: string, command: 'build' | 'serve' }) { // 只在开发环境(serve命令)时生成代理配置 const isDev = command === 'serve' @@ -66,9 +66,11 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti } if (!enableProxy || !isDev) { - // 在非开发环境下,生成原始地址映射(path 和 rawPath 都是原始地址) + // 在非开发环境下,根据构建模式选择正确的环境配置 + const targetEnv = isDev ? devEnvName : mode const rawMapping: ProxyMapping = {} - const envConfig = serviceConfig[devEnvName] + const envConfig = serviceConfig[targetEnv] + if (envConfig) { Object.entries(envConfig).forEach(([serviceName, serviceUrl]) => { rawMapping[serviceName] = { @@ -76,7 +78,12 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti rawPath: serviceUrl, } }) + console.warn(`[auto-proxy] 已加载 ${Object.keys(envConfig).length} 个服务地址`) } + else { + console.warn(`[auto-proxy] 未找到环境 "${targetEnv}" 的配置`) + } + config.define[envName] = JSON.stringify(rawMapping) // 生成 d.ts 类型文件(如果指定了路径) diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index a661423..0000000 --- a/netlify.toml +++ /dev/null @@ -1,17 +0,0 @@ -[build] -publish = "dist" -command = "vite build --mode prod" - -[build.environment] -NODE_VERSION = "20" - -[[redirects]] -from = "/*" -to = "/index.html" -status = 200 - -[[headers]] -for = "/manifest.webmanifest" - -[headers.values] -Content-Type = "application/manifest+json" diff --git a/package.json b/package.json index bbf42d8..6a9e5c7 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ ], "scripts": { "dev": "vite --mode dev --port 9980", - "dev:prod": "vite --mode prod", - "build": "vite build --mode prod", + "dev:prod": "vite --mode production", + "build": "vite build", "build:dev": "vite build --mode dev", "preview": "vite preview --port 9981", "lint": "eslint . && vue-tsc --noEmit", diff --git a/service.config.ts b/service.config.ts index 1f6b657..1dcdaf8 100644 --- a/service.config.ts +++ b/service.config.ts @@ -3,7 +3,7 @@ export const serviceConfig: Record> = { dev: { url: 'http://localhost:3000', }, - prod: { + production: { url: 'https://mock.apifox.cn/m1/4071143-0-default', }, } diff --git a/src/typings/env.d.ts b/src/typings/env.d.ts index 4c2c4de..48b778e 100644 --- a/src/typings/env.d.ts +++ b/src/typings/env.d.ts @@ -3,7 +3,7 @@ * - dev: 后台开发环境 * - prod: 后台生产环境 */ -type ServiceEnvType = 'dev' | 'prod' +type ServiceEnvType = 'dev' | 'production' interface ImportMetaEnv { /** 项目基本地址 */