Merge pull request #162 from liuqi-web/manifest.config-env

fix:test模式环境变量加载不正确问题和H5时base同步问题
This commit is contained in:
菲鸽
2025-06-27 18:16:57 +08:00
committed by GitHub
2 changed files with 10 additions and 3 deletions

View File

@@ -4,8 +4,14 @@ import process from 'node:process'
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
import { loadEnv } from 'vite'
// 手动解析命令行参数获取 mode
function getMode() {
const args = process.argv.slice(2)
const modeFlagIndex = args.findIndex(arg => arg === '--mode')
return modeFlagIndex !== -1 ? args[modeFlagIndex + 1] : args[0] === 'build' ? 'production' : 'development' // 默认 development
}
// 获取环境变量的范例
const env = loadEnv(process.env.NODE_ENV!, path.resolve(process.cwd(), 'env'))
const env = loadEnv(getMode(), path.resolve(process.cwd(), 'env'))
const {
VITE_APP_TITLE,
VITE_UNI_APPID,
@@ -24,7 +30,7 @@ export default defineManifestConfig({
'locale': VITE_FALLBACK_LOCALE, // 'zh-Hans'
'h5': {
router: {
base: VITE_APP_PUBLIC_BASE,
// base: VITE_APP_PUBLIC_BASE,
},
},
/* 5+App特有相关 */

View File

@@ -50,12 +50,13 @@ export default async ({ command, mode }) => {
VITE_SHOW_SOURCEMAP,
VITE_APP_PROXY,
VITE_APP_PROXY_PREFIX,
VITE_APP_PUBLIC_BASE
} = env
console.log('环境变量 env -> ', env)
return defineConfig({
envDir: './env', // 自定义env目录
base: VITE_APP_PUBLIC_BASE,
plugins: [
UniPages({
exclude: ['**/components/**/**.*'],