From 8ac4c3546426fc5e8b7daf2bea6dd6c44568b286 Mon Sep 17 00:00:00 2001 From: Songsl <2431955898@qq.com> Date: Wed, 22 Apr 2026 14:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index e91679d..e8c97d2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,5 +1,5 @@ import { fileURLToPath, URL } from 'node:url' -import { defineConfig } from 'vite' +import { loadEnv, defineConfig, ConfigEnv, ViteConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueDevTools from 'vite-plugin-vue-devtools' @@ -11,9 +11,9 @@ import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' // https://vite.dev/config/ -export default defineConfig(({ mode }) => { +export default defineConfig(({ mode }: ConfigEnv): ViteConfig => { const isProduction = mode === 'production' - + const env = loadEnv(mode, process.cwd()) return { plugins: [ vue(), @@ -51,8 +51,8 @@ export default defineConfig(({ mode }) => { manualChunks: { // 将第三方库单独分包 'element-plus': ['element-plus', '@element-plus/icons-vue'], - 'vendor': ['vue', 'vue-router', 'pinia'], - 'utils': ['axios', 'dayjs', 'crypto-js', '@vueuse/core'], + vendor: ['vue', 'vue-router', 'pinia'], + utils: ['axios', 'dayjs', 'crypto-js', '@vueuse/core'], }, // 文件名带 hash(缓存优化) chunkFileNames: 'assets/js/[name]-[hash].js', @@ -81,7 +81,16 @@ export default defineConfig(({ mode }) => { server: { host: true, + port: 9999, + https: false, + open: true, + proxy: { + '/api': { + target: env.VITE_API_BASE_URL, + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, ''), + }, + }, }, } }) -