f
This commit is contained in:
@@ -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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user