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

Taro3.0.5 主包没有引用taro-ui,分包页面引入taro-ui,taro-ui被打进主包 #7176

Closed
Carnia opened this issue Jul 27, 2020 · 3 comments
Assignees
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@Carnia
Copy link

Carnia commented Jul 27, 2020

相关平台

微信小程序

小程序基础库: 2.12.0
使用框架: React

复现步骤

app.config.ts

  ...
  pages: [
    'omodule/app-home/pages/Page1',
    'omodule/app-home/pages/Page2',
    'omodule/app-home/pages/Page3',
  ],
  subpackages: [
    {
      name: 'common',
      root: 'module/common/',
      pages: ['pages/webview/index'],
  },
  ...

prod.js

...
mini: {
    webpackChain(chain) {
      chain.merge({
        optimization: {
          splitChunks: {
            cacheGroups: {
              'customPackage/taroui': {
                chunks: 'all',
                test: /taro\-ui/,
                name: 'customPackage/taroui',
                minChunks: 1,
                maxInitialRequests: 5,
                minSize: 0,
                priority: 100,
              },
            },
          },
        }
      })
      chain.plugin('analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
    },
    addChunkPages (pages, pagesNames) {
      pages.set('module/common/pages/webview/index', ['customPackage/taroui'])
    }
  },
...

module/common/pages/webview/index中我引用了taro-ui
在主包的三个页面中没有引用,我按照mini addchunkpages这个api,并且参考一些之前的issue。最后打出来的包中存在customPackage/taroui.js等文件,是有customPackage这个文件夹的。按照此描述应该是没问题的。但是主包还是变大了,分包没有变大。

期望结果

taro-ui被剔除微信主包。

实际结果

taro-ui在微信主包内,并且由于其他页面存在的原因超出2m的大小限制,上述例子中我剔除了所有其他不相关页面。

环境信息

Taro CLI 2.2.6 environment info:
    System:
      OS: macOS 10.15
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 13.9.0 - ~/.nvm/versions/node/v13.9.0/bin/node
      Yarn: 1.22.0 - ~/.yarn/bin/yarn
      npm: 6.13.7 - ~/.nvm/versions/node/v13.9.0/bin/npm
    npmPackages:
      @tarojs/cli: ^3.0.5 => 3.0.5 
      @tarojs/components: ^3.0.5 => 3.0.5 
      @tarojs/mini-runner: ^3.0.5 => 3.0.5 
      @tarojs/taro: ^3.0.5 => 3.0.5 
      @tarojs/webpack-runner: ^3.0.5 => 3.0.5 
      eslint-config-taro: 3.0.0-rc.3 => 3.0.0-rc.3 
      nerv-devtools: ^1.5.7 => 1.5.7 
      nervjs: ^1.5.7 => 1.5.7 
      react: ^16.10.0 => 16.13.1 
      taro-ui: ^3.0.0-alpha.2 => 3.0.0-alpha.3 
    npmGlobalPackages:
      typescript: 3.5.3
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Jul 27, 2020
@Carnia
Copy link
Author

Carnia commented Jul 27, 2020

我不知道我的用法对不对,但是一直没有生效,烦请救救我的头发。

@Carnia
Copy link
Author

Carnia commented Jul 30, 2020

更通俗一点的是:
1、当整个小程序只在分包B中的1个页面包含 某个库a 时,这个库a会被被打入分包
2、当整个小程序只在分包B中有2个页面包含 某个库a 时,这个库a会被被打入主包
第二种情况中,主包压根就和库a没有关系。

我本以为能用mini addchunkpages去解决这个问题:单独为库a打一个分包C,然后用mini addchunkpages去为相关页面指定引用分包C。但是实际上没有效果,结果依旧如上。

@luckyadam
Copy link
Member

因为没有 customPackage 这样一个名字目录的分包,它依然还是属于主包的文件, 如果你想让他属于分包,那就应该放到分包的目录下,例如 module

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

No branches or pull requests

2 participants