From 76cba05ef1ada9cee60e9d5eb8065ae4e7587c25 Mon Sep 17 00:00:00 2001 From: Abner <22141172+Silentely@users.noreply.github.com> Date: Fri, 17 Jul 2026 20:53:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore:=20=E8=84=B1=E9=93=BE?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E8=A6=86=E7=9B=96=20dist=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E4=BA=A7=E7=89=A9=20HTML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在已构建时同步校验 dist 入口资源,未构建时跳过 dist 避免误报。 --- scripts/check-asset-links.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/scripts/check-asset-links.js b/scripts/check-asset-links.js index fed2a54..84cf964 100644 --- a/scripts/check-asset-links.js +++ b/scripts/check-asset-links.js @@ -14,7 +14,11 @@ const projectRoot = path.join(__dirname, '..'); const htmlRoots = [ path.join(projectRoot, 'index.html'), path.join(projectRoot, 'src', 'giffgaff', 'giffgaff_modular.html'), - path.join(projectRoot, 'src', 'simyo', 'simyo_modular.html') + path.join(projectRoot, 'src', 'simyo', 'simyo_modular.html'), + // 若已构建,同步校验发布产物(与源入口路径对应) + path.join(projectRoot, 'dist', 'index.html'), + path.join(projectRoot, 'dist', 'src', 'giffgaff', 'giffgaff_modular.html'), + path.join(projectRoot, 'dist', 'src', 'simyo', 'simyo_modular.html') ]; const ATTR_RE = /\b(?:src|href)=["']([^"']+)["']/gi; @@ -74,14 +78,19 @@ function main() { let checked = 0; for (const htmlPath of htmlRoots) { + const relHtml = path.relative(projectRoot, htmlPath); + const isDistEntry = relHtml.startsWith(`dist${path.sep}`) || relHtml.startsWith('dist/'); + + // dist 入口仅在已构建时检查,避免未 build 时误报 if (!fs.existsSync(htmlPath)) { - missing.push({ file: htmlPath, url: '(file missing)', reason: 'HTML 入口不存在' }); + if (!isDistEntry) { + missing.push({ file: relHtml, url: '(file missing)', reason: 'HTML 入口不存在' }); + } continue; } const html = fs.readFileSync(htmlPath, 'utf8'); const urls = collectUrls(html); - const relHtml = path.relative(projectRoot, htmlPath); for (const url of urls) { if (shouldSkip(url)) continue; @@ -89,12 +98,21 @@ function main() { if (!resolved) continue; checked++; - const exists = resolved.candidates.some((p) => fs.existsSync(p)); + // dist HTML 优先解析到 dist 下;源 HTML 源码与 dist 任一存在即可 + const candidates = isDistEntry + ? [ + path.join(projectRoot, 'dist', resolved.clean.slice(1)), + path.join(projectRoot, resolved.clean.slice(1)) + ] + : resolved.candidates; + const exists = candidates.some((p) => fs.existsSync(p)); if (!exists) { missing.push({ file: relHtml, url: resolved.clean, - reason: '本地文件不存在(源码与 dist 均未找到)' + reason: isDistEntry + ? '构建产物中资源不存在' + : '本地文件不存在(源码与 dist 均未找到)' }); } }