From 127783bbe780c443a3a8c727f7b9cc988ca02ee9 Mon Sep 17 00:00:00 2001 From: zhaoruhui Date: Thu, 16 Oct 2025 16:09:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/vite.config.js b/vite.config.js index 3c0e1cd..48161ef 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,16 +1,21 @@ import { fileURLToPath, URL } from 'node:url' -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import vueDevTools from 'vite-plugin-vue-devtools' // https://vite.dev/config/ export default defineConfig(({ mode, command }) => { + // 加载环境变量 + const env = loadEnv(mode, process.cwd(), '') + const outDirMap = { development: 'dist-test', product: 'dist-prod' } return { + // 确保基础路径正确 + base: './', plugins: [ vue(), vueDevTools(), @@ -29,9 +34,8 @@ export default defineConfig(({ mode, command }) => { guide: './hcdbqb-guide.html', management: './hcdbqb-management.html' }, - // 配置代码分割 output: { - manualChunks: undefined, // 禁用自动代码分割 + manualChunks: undefined, chunkFileNames: 'assets/[name]-[hash].js', entryFileNames: 'assets/[name]-[hash].js' } @@ -40,6 +44,11 @@ export default defineConfig(({ mode, command }) => { server: { port: 5173, open: true + }, + // 确保环境变量在构建时被正确处理 + define: { + 'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL), + 'import.meta.env.VITE_APP_ENV': JSON.stringify(env.VITE_APP_ENV) } } }) \ No newline at end of file