From 44dd9c4eb8a2489c63a5eb53fd4254bbb3510e95 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Thu, 18 Jun 2026 09:14:57 +0800
Subject: [PATCH] Merge branch 'feature/v9.0/9.0.4'
---
vite.config.js | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/vite.config.js b/vite.config.js
index f77f5cb..8d7f591 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -3,20 +3,29 @@
import { defineConfig, loadEnv } from "vite"
import { createViteProxy } from "./build/config/index"
import createVitePlugins from "./build/plugins/index"
+import configEnv from "./src/config/env.js";
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
// mode: 区分生产环境还是开发环境
console.log("command, mode -> ", command, mode)
- const { UNI_PLATFORM } = process.env
- console.log("UNI_PLATFORM -> ", UNI_PLATFORM) // 得到 mp-weixin, h5, app 等
+ const { UNI_PLATFORM,UNI_CUSTOM_DEFINE } = process.env
+ const ENV_NAME = UNI_CUSTOM_DEFINE && JSON.parse(UNI_CUSTOM_DEFINE)?.ENV_NAME
+ const __APP_ENV__ = {
+ UNI_PLATFORM: UNI_PLATFORM,
+ ENV_NAME: ENV_NAME || 'development'
+ }
+ console.log("平台 -> ", __APP_ENV__.UNI_PLATFORM) // 得到 mp-weixin, h5, app 等
+ console.log("环境 -> ", __APP_ENV__.ENV_NAME) // 得到 development,test 等
const env = loadEnv(mode, fileURLToPath(new URL("./env", import.meta.url)))
- console.log("环境变量 env -> ", env)
-
+ // console.log("环境变量 env -> ", env)
const isBuild = process.env.NODE_ENV === "production"
return {
+ define: {
+ __APP_ENV__,
+ },
// 自定义env目录
envDir: "./env",
resolve: {
@@ -32,7 +41,7 @@
hmr: true,
host: true,
open: true,
- proxy: createViteProxy(env)
+ proxy: createViteProxy(env,__APP_ENV__.ENV_NAME)
},
// 设置scss的api类型为modern-compiler
css: {
--
Gitblit v1.9.3