From 27835e73ac5ffab65ed212f5294639a3a4b784ae Mon Sep 17 00:00:00 2001 From: tao Date: Tue, 30 Sep 2025 15:44:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=A8=E5=B1=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 5 ++- .env.production | 4 ++- global.d.ts | 3 +- src/api/request.ts | 4 +-- vite.config.ts | 83 ++++++++++++++++++++++++---------------------- 5 files changed, 54 insertions(+), 45 deletions(-) diff --git a/.env.development b/.env.development index 5c3cf8d..dafeb3c 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,5 @@ # 开发环境 -VITE_APP_BASE_API = '/api' \ No newline at end of file +VITE_APP_BASE_API='/api' + + +VITE_APP_BASE_URL='http://192.168.1.38:18081' \ No newline at end of file diff --git a/.env.production b/.env.production index c75f02a..a2d8567 100644 --- a/.env.production +++ b/.env.production @@ -1,2 +1,4 @@ # 生产环境 -VITE_APP_BASE_API = '/prod-api' \ No newline at end of file +VITE_APP_BASE_API=/prod-api + +VITE_APP_BASE_URL=http://127.0.0.1:18081 \ No newline at end of file diff --git a/global.d.ts b/global.d.ts index bc8a495..36160f9 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,5 +1,4 @@ // declare module '@/*'; declare module '@/components/*'; declare module '@/views/*'; -declare module '@/api/*'; -declare module '@/App.vue'; +declare module '@/api/*'; \ No newline at end of file diff --git a/src/api/request.ts b/src/api/request.ts index 174ccc3..a960bbc 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -13,7 +13,7 @@ const errCodeMap: { [key: string]: string } = { // 创建axios实例 const service = axios.create({ - baseURL: import.meta.env.VITE_APP_BASE_API as string, + baseURL: import.meta.env.VITE_APP_BASE_API, timeout: 10000, }); @@ -37,7 +37,7 @@ service.interceptors.request.use( // 响应拦截器 service.interceptors.response.use( response => { - console.log(response) + // console.log(response); const code = response.data.code || 200; const data = response.data; diff --git a/vite.config.ts b/vite.config.ts index 7b19189..ba80cf2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import Components from "unplugin-vue-components/vite"; // 按需组件自动导入 import { AntDesignVueResolver } from "unplugin-vue-components/resolvers"; import vue from '@vitejs/plugin-vue'; @@ -7,44 +7,49 @@ import IconsResolver from 'unplugin-icons/resolver'; import path from 'path'; // https://vite.dev/config/ -export default defineConfig({ - resolve: { - alias: { - "@": path.resolve(__dirname, "src"), - }, - }, - server: { - proxy: { - "/api": { - target: "http://192.168.1.38:18081", - changeOrigin: true, - rewrite: (path) => path.replace(/^\/api/, ""), - }, - "/prod-api": { - target: "http://127.0.0.1:18081", - changeOrigin: true, +export default defineConfig(({ mode }) => { + + const env = loadEnv(mode, process.cwd()); + + return { + resolve: { + alias: { + "@": path.resolve(__dirname, "src"), }, }, - }, - plugins: [ - vue(), - Components({ - dts: true, //生成components.d.ts 全局定义文件 - resolvers: [ - AntDesignVueResolver({ - //对使用到的全局ant design vue组件进行类型导入 - importStyle: false, // 不动态引入css,这个不强求 - }), - // 自动导入 lucide 图标 - IconsResolver({ - prefix: "i", // 比如用 - enabledCollections: ["lucide"], - }), - ], - include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx$/], //包含的文件类型 - }), - Icons({ - autoInstall: true, // 没安装的图标库会自动下载 - }), - ], + server: { + proxy: { + "/api": { + target: env.VITE_APP_BASE_URL, + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, ""), + }, + "/prod-api": { + target: env.VITE_APP_BASE_URL, + changeOrigin: true, + }, + }, + }, + plugins: [ + vue(), + Components({ + dts: true, //生成components.d.ts 全局定义文件 + resolvers: [ + AntDesignVueResolver({ + //对使用到的全局ant design vue组件进行类型导入 + importStyle: false, // 不动态引入css,这个不强求 + }), + // 自动导入 lucide 图标 + IconsResolver({ + prefix: "i", // 比如用 + enabledCollections: ["lucide"], + }), + ], + include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx$/], //包含的文件类型 + }), + Icons({ + autoInstall: true, // 没安装的图标库会自动下载 + }), + ], + } });