wepy icon indicating copy to clipboard operation
wepy copied to clipboard

tab下挂载插件页面时,wepy报错

Open scott-leung opened this issue 3 years ago • 2 comments

Description

最近接到一个需求,需要在小程序原生 Tab 中跳转插件页面。

那么就有 tab 设置代码如下:

tabBar: {
  list: [{
    text: '首页',
    pagePath: 'pages/index',
    iconPath: '/images/index.png',
    selectedIconPath: '/images/index_sel.png'
  }, {
    text: '购物袋',
    pagePath: '__plugin__/wx34345ae5855f892d/pages/shoppingCart/shoppingCart',
    iconPath: '/images/cart.png',
    selectedIconPath: '/images/cart_sel.png'
  }],
  position: 'bottom'
},

由于这里时跳转到插件路径,插件已发布并且不在项目文件中。

这时候项目跑起来,开发者工具提示没有在 app.json 中找到相应的页面路径配置。

于是我们在 pages 中配置路径如下:

pages: [
  'pages/index',
  '__plugin__/wx34345ae5855f892d/pages/shoppingCart/shoppingCart'
],

保存之,这时 wepy 报错:

[17:56:30] info build app start...
[17:56:31] ERR! Message:
[17:56:31] ERR!   Can not resolve page: D:\code\xxx\src\__plugin__\wx34345ae5855f892d\pages\shoppingCart\shoppingCart
[17:56:31] ERR! File:
[17:56:31] ERR!   D:\code\xxx\src\app.wpy
[17:56:31] info app building App
[17:56:32] info component building components
[17:56:32] ERR! Cannot read property 'sfc' of undefined
[17:56:32] ERR! compile Compile failed. Add "--log trace" to see more details
[17:56:32] info watching...

虽然报错,但项目还是可以跑的,但觉得这个报错还是要解决下。

看了一下工具的代码,我作出了以下改动以支持该特性:

  • appConfig.pages.map 时,过滤页面名称后再 map;
  • sub.pages.forEach 时,过滤页面名称后再 forEach;
  • 新增过滤函数;
// packages/cli/core/compile.js - line 209 brefore update
let pages = appConfig.pages.filter(filterPagePath).map(v => {
  return path.resolve(app.file, '..', v);
});

// packages/cli/core/compile.js - line 223 before update
sub.pages.filter(filterPagePath).forEach(v => {
  pages.push(path.resolve(app.file, '../' + sub.root || '', v));
});

// filterPagePath add to line 30.
// 过滤出合法的页面路径
function filterPagePath(pagePath) {
  // 这里暂时只考虑过滤 __plugin__/ 开头的页面路径
  return pagePath.indexOf('__plugin__/') !== 0;
}

PR 基本准备好了。稍后提上哈~

Environment

  • Platform: 开发者工具
  • Platform version: 1.03.2011120
  • Wechat version: 7.0.18
  • wepy-cli version: 2.1.0
  • wepy version: 2.1.0
  • other version: none

Reproduce

  1. 使用任一插件,并在 tab 设置中添加其插件路径;
  2. pages 中添加其插件路径;
  3. 保存,编译,此时 wepy 工具报错,但能正常往下;

Observed Results

wepy 工具报错,其他流程正常。

Expected Results

wepy 工具对此情况不进行报错,其他流程正常。

Relevant Code / Logs

no more.

scott-leung avatar Dec 02 '20 07:12 scott-leung

__plugin__ 这个有相关的文档吗?

Gcaufy avatar Dec 05 '20 02:12 Gcaufy

__plugin__ 这个有相关的文档吗?

这个暂时没有文档公开,可以说属于未公开的可用功能之一。

scott-leung avatar Dec 05 '20 15:12 scott-leung