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 })