diff --git a/pages.json b/pages.json index 56ff5c6..b7e8d21 100644 --- a/pages.json +++ b/pages.json @@ -218,7 +218,63 @@ { "path": "detail", "style": { - "navigationBarTitleText": "商品详情" + "navigationBarTitleText": "商品详情", + "componentPlaceholder": { + "diy-article": "view", + "diy-audio": "view", + "diy-bargain": "view", + "diy-bottom-nav": "view", + "diy-category": "view", + "diy-category-item": "view", + "diy-channel-list": "view", + "diy-channel-video": "view", + "diy-comp-extend": "view", + "diy-coupon": "view", + "diy-digit": "view", + "diy-fenxiao-goods-list": "view", + "diy-float-btn": "view", + "diy-follow-official-account": "view", + "diy-form": "view", + "diy-goods-brand": "view", + "diy-goods-list": "view", + "diy-goods-recommend": "view", + "diy-graphic-nav": "view", + "diy-group": "view", + "diy-groupbuy": "view", + "diy-horz-blank": "view", + "diy-horz-line": "view", + "diy-hot-area": "view", + "diy-icon": "view", + "diy-image-nav": "view", + "diy-img-ads": "view", + "diy-index-page": "view", + "diy-kefu": "view", + "diy-listmenu": "view", + "diy-live": "view", + "diy-many-goods-list": "view", + "diy-map": "view", + "diy-member-info": "view", + "diy-member-my-order": "view", + "diy-merch-list": "view", + "diy-notes": "view", + "diy-notice": "view", + "diy-payment-qrcode": "view", + "diy-picture": "view", + "diy-pinfan": "view", + "diy-pintuan": "view", + "diy-presale": "view", + "diy-quick-nav": "view", + "diy-rich-text": "view", + "diy-rubik-cube": "view", + "diy-search": "view", + "diy-seckill": "view", + "diy-store": "view", + "diy-store-label": "view", + "diy-tab": "view", + "diy-text": "view", + "diy-video": "view", + "diy-video-list": "view" + } } }, { diff --git a/scripts/inject-placeholder.js b/scripts/inject-placeholder.js index edc79d3..ad10a84 100644 --- a/scripts/inject-placeholder.js +++ b/scripts/inject-placeholder.js @@ -99,18 +99,69 @@ function lastMeaningfulIdx(bodyLines) { } /** - * 检查 page 的 .vue 文件是否引用了 组件. - * 简单的字符串检查, 包含 . + */ +const _usesDiyCache = new Map(); +const _importRe = /import\s+[^'"`;\n]*['"]([^'"`]+\.vue)['"]/g; + +/** + * 检查一个 .vue 文件是否(传递)使用了 组件. + * 不仅看模板里是否含 + */ +function fileUsesDiy(relVuePath) { + if (!relVuePath) return false; + if (_usesDiyCache.has(relVuePath)) return _usesDiyCache.get(relVuePath); + // 暂存 false 以打破循环引用 + _usesDiyCache.set(relVuePath, false); + const abs = path.join(PROJECT_ROOT, relVuePath + '.vue'); + let content; + try { + content = fs.readFileSync(abs, 'utf-8'); + } catch (e) { + return false; + } + if (/ 组件. + * fullPagePath 是 pages.json 中拼接的页面路径, 如 "pages_goods/detail". */ function pageUsesDiy(fullPagePath) { - if (!fullPagePath) return false; - const vuePath = path.join(PROJECT_ROOT, fullPagePath + '.vue'); - try { - const content = fs.readFileSync(vuePath, 'utf-8'); - return /