This commit is contained in:
Mrx
2026-05-06 16:42:58 +08:00
parent 973432b637
commit 3063ecb1f2
3 changed files with 36 additions and 4 deletions

View File

@@ -1,6 +1,10 @@
import path from 'node:path'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
// 用配置文件所在目录作为项目根,避免从 monorepo 根目录执行命令时 loadEnv 读不到子项目 .env
const projectRoot = path.dirname(fileURLToPath(new URL(import.meta.url)))
import Components from '@uni-helper/vite-plugin-uni-components'
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
import { ZPagingResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
@@ -14,8 +18,8 @@ import Uni from '@uni-helper/plugin-uni'
import UnoCSS from 'unocss/vite'
export default defineConfig(({ mode }) => {
// 加载环境变量(.env / .env.development / .env.production
const env = loadEnv(mode, process.cwd(), '')
// 加载环境变量(.env / .env.development / .env.production.env.local 会覆盖同名字段
const env = loadEnv(mode, projectRoot, '')
const apiUrl = env.VITE_API_URL || ''
const apiPrefix = env.VITE_API_PREFIX || '/api'