From 00870e45548d8a6aa9e610228c1bd9dad93164c5 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Thu, 28 May 2026 14:36:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(vue.config&manifest):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B7=AF=E7=94=B1base=E8=B7=AF=E5=BE=84=E8=A1=A5=E5=85=A8?= =?UTF-8?q?=E5=92=8C=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 调整manifest.json中router.base默认路径补全末尾斜杠 2. 在vue.config.js中增加base路径校验,自动补全缺失的末尾斜杠并打印警告 --- manifest.json | 2 +- vue.config.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index 6147525..f2c52f8 100644 --- a/manifest.json +++ b/manifest.json @@ -107,7 +107,7 @@ }, "router" : { "mode" : "history", - "base" : "/hwappx/common" + "base" : "/hwappx/common/" }, "title" : "", "devServer" : { diff --git a/vue.config.js b/vue.config.js index ae55ea4..74bf2b9 100644 --- a/vue.config.js +++ b/vue.config.js @@ -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);