Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

动态给app.config.ts的pages字段添加页面,新增的页面没有被编译 #10224

Open
bigmeow opened this issue Sep 6, 2021 · 1 comment
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@bigmeow
Copy link
Member

bigmeow commented Sep 6, 2021

使用场景

我定义了一套类似于vue-router的路由配置,我写了一个插件来解析自己路由配置,动态生成小程序所需要的app.jsonpages

相关平台

微信小程序

复现仓库

https://github.com/bigmeow/taro-bug-demo
小程序基础库: 无
使用框架: Vue 3

复现步骤

我新增了一个taro插件, 插件作用是动态修改 小程序的配置文件app.config.ts, 在插件里我给pages数组新加了一个页面,然后新加的页面并没有被编译。
插件代码:

module.exports = (ctx, pluginOpts) => {

    ctx.modifyMiniConfigs(({ configMap }) => {
        console.log("动态添加app.config中的pages字段")
        configMap["app.config"].content.pages.push("pages/index2/index")
        console.log(configMap["app.config"].content.pages)
    })
}

重现步骤:

  1. 克隆demo
  2. npm i
  3. npm run build:weapp

期望结果

打开dist/pages目录,希望看到动态新增的pages/index2/index被编译

实际结果

编译后无pages/index2/index页面

环境信息

👽 Taro v3.3.6


  Taro CLI 3.3.6 environment info:
    System:
      OS: macOS 11.5.2
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.17.5 - ~/.nvm/versions/node/v14.17.5/bin/node
      Yarn: 1.22.11 - /usr/local/bin/yarn
      npm: 6.14.14 - ~/.nvm/versions/node/v14.17.5/bin/npm
    npmPackages:
      @tarojs/components: 3.3.6 => 3.3.6 
      @tarojs/mini-runner: 3.3.6 => 3.3.6 
      @tarojs/runtime: 3.3.6 => 3.3.6 
      @tarojs/taro: 3.3.6 => 3.3.6 
      @tarojs/webpack-runner: 3.3.6 => 3.3.6 
      babel-preset-taro: 3.3.6 => 3.3.6 
      eslint-config-taro: 3.3.6 => 3.3.6 
@taro-bot2 taro-bot2 bot added F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Sep 6, 2021
@b2nil
Copy link
Collaborator

b2nil commented Sep 7, 2021

确实 modifyMiniConfigs 目前只是修改了 filesConfig,没有相应修改 this.pages。调后 modifyMiniConfigs 后,再调用一次 this.getPages() 就没问题了。

if (typeof modifyMiniConfigs === 'function') {
await modifyMiniConfigs(this.filesConfig)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants