fix(vue.config&manifest): 修复路由base路径补全和校验逻辑

1.  调整manifest.json中router.base默认路径补全末尾斜杠
2.  在vue.config.js中增加base路径校验,自动补全缺失的末尾斜杠并打印警告
This commit is contained in:
2026-05-28 14:36:23 +08:00
parent 233093bebb
commit 00870e4554
2 changed files with 7 additions and 3 deletions

View File

@@ -107,7 +107,7 @@
},
"router" : {
"mode" : "history",
"base" : "/hwappx/common"
"base" : "/hwappx/common/"
},
"title" : "",
"devServer" : {

View File

@@ -74,11 +74,15 @@ try {
function _readManifestBase(manifestPath) {
try {
const raw = fs.readFileSync(manifestPath, 'utf8');
// 去掉 /* */ 和 // 注释(HBuilder 生成的 JSON 允许注释)
const clean = raw.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
const manifest = JSON.parse(clean);
if (manifest?.h5?.router?.base) {
return manifest.h5.router.base.replace(/^\/+|\/+$/g, '').replace(/\//g, '.');
let base = manifest.h5.router.base;
if (!base.endsWith('/')) {
console.warn(`[manifest] h5.router.base "${base}" 不规范,已自动补全 /`);
base = base + '/';
}
return base.replace(/^\/+|\/+$/g, '').replace(/\//g, '.');
}
} catch (e) {
console.warn('[manifest] 读取 h5.router.base 失败:', e.message);