From 1284698948469446d0622e45ea3fe14f660673c4 Mon Sep 17 00:00:00 2001 From: mamamiyear Date: Tue, 28 Oct 2025 00:20:53 +0800 Subject: [PATCH] chore: use different base url for different output --- .env | 2 ++ .env.production | 2 ++ src/apis/config.ts | 2 +- vite.config.ts | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .env create mode 100644 .env.production diff --git a/.env b/.env new file mode 100644 index 0000000..26c53db --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +# 开发环境配置 +VITE_API_BASE_URL=http://127.0.0.1:8099 \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..6e5578e --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +# 生产环境配置 +VITE_API_BASE_URL=http://47.109.95.59:20080 \ No newline at end of file diff --git a/src/apis/config.ts b/src/apis/config.ts index 352809b..20f8397 100644 --- a/src/apis/config.ts +++ b/src/apis/config.ts @@ -1,7 +1,7 @@ // API 配置 export const API_CONFIG = { - BASE_URL: 'http://127.0.0.1:8099', + BASE_URL: import.meta.env.VITE_API_BASE_URL || 'http://127.0.0.1:8099', TIMEOUT: 10000, HEADERS: { 'Content-Type': 'application/json', diff --git a/vite.config.ts b/vite.config.ts index 8b0f57b..f1d41c6 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + // Vite 默认支持环境变量,无需额外配置 + // 环境变量加载优先级: + // .env.local > .env.[mode] > .env })