From 6abe1fff9efa48b840a61e19ec15f00640ef3c62 Mon Sep 17 00:00:00 2001 From: Burt <1020103647@qq.com> Date: Sat, 23 Dec 2023 12:10:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(http):=20baseUrl=20=E5=AF=B9=E6=8E=A5=20VI?= =?UTF-8?q?TE=5FSERVER=5FBASEURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env/.env.development | 2 +- env/.env.production | 2 +- env/.env.test | 2 +- src/env.d.ts | 2 ++ src/utils/http.ts | 2 +- tsconfig.json | 1 + 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/env/.env.development b/env/.env.development index 2dd582a..522d32a 100644 --- a/env/.env.development +++ b/env/.env.development @@ -1,6 +1,6 @@ # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV = 'development' -VITE_API_SERVER = 'http://localhost:4000' +VITE_SERVER_BASEURL = 'http://localhost:4000' # 是否去除console 和 debugger VITE_DELETE_CONSOLE = false diff --git a/env/.env.production b/env/.env.production index 9d96791..a5bf16f 100644 --- a/env/.env.production +++ b/env/.env.production @@ -1,6 +1,6 @@ # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV = 'development' -VITE_API_SERVER = 'https://xxx.com' +VITE_SERVER_BASEURL = 'https://xxx.com' # 是否去除console 和 debugger VITE_DELETE_CONSOLE = true diff --git a/env/.env.test b/env/.env.test index 3d8defa..01a64fd 100644 --- a/env/.env.test +++ b/env/.env.test @@ -1,6 +1,6 @@ # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV = 'development' -VITE_API_SERVER = 'https://xxx.com' +VITE_SERVER_BASEURL = 'https://xxx.com' # 是否去除console 和 debugger VITE_DELETE_CONSOLE = false diff --git a/src/env.d.ts b/src/env.d.ts index 0afd433..fa8c7d8 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -11,6 +11,8 @@ declare module '*.vue' { interface ImportMetaEnv { readonly VITE_APP_TITLE: string readonly VITE_SERVER_PORT: string + readonly VITE_SERVER_BASEURL: string + readonly VITE_DELETE_CONSOLE: string // 更多环境变量... } diff --git a/src/utils/http.ts b/src/utils/http.ts index 35c84fb..80c4b22 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -10,7 +10,7 @@ type Data = { } // 请求基地址 -const baseURL = 'http://localhost:5565/api' +const baseURL = import.meta.env.VITE_SERVER_BASEURL // 拦截器配置 const httpInterceptor = { diff --git a/tsconfig.json b/tsconfig.json index 7520ba3..9593800 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "module": "ESNext", "sourceMap": true, "baseUrl": ".", "paths": {