This commit is contained in:
feige996
2025-06-27 19:15:21 +08:00
2 changed files with 9 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

@@ -56,7 +56,7 @@ export default async ({ command, mode }) => {
return defineConfig({
envDir: './env', // 自定义env目录
base: VITE_APP_PUBLIC_BASE, // TODO check
base: VITE_APP_PUBLIC_BASE,
plugins: [
UniPages({
exclude: ['**/components/**/**.*'],