diff --git a/manifest.config.ts b/manifest.config.ts index b498ca4..503f85f 100644 --- a/manifest.config.ts +++ b/manifest.config.ts @@ -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特有相关 */ diff --git a/vite.config.ts b/vite.config.ts index d673f29..9409682 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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/**/**.*'],