npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

taro-plugin-subpackage-optimize

v0.1.1

Published

Taro 小程序分包优化

Downloads

7

Readme

taro-plugin-subpackage-optimize

Taro 3.x 小程序端分包优化

背景

默认情况下,任意一个模块只要被引用两次以上都会被提取到主包中。比如:

subPackages
  package-1    # 分包根目录
    components
      share
    pages
      foo
      bar

假设 foobar 都引用了 share,那么 share 默认会被提取到主包的 common.js 中, 尽管它只在分包中用到。

这无疑给寸土寸金的主包空间造成较大的压力。

理想情况下,只在分包中引用到的模块应该放在分包中, 没有必要放在主包:

node_modules
  some-npm-package
src
  app.tsx
  pages
    # ...
  components
    button.tsx
  subPackages
    # ...
    package-1    # 分包根目录
      components
        share.tsx
      pages
        foo.tsx
        bar.tsx

如果 some-npm-packagecomponents/button.tsx、 以及 package-1 下的所有模块,只在 package-1下的模块引用,那么这些依赖模块就应该放在 package-1 分包根目录下。

taro-plugin-subpackage-optimize 就是做这个工作。开启 taro-plugin-subpackage-optimize 输出结果如下:

src
  app.js
  app.json
  pages
    # ...
  subPackages
    # ...
    package-1    # 分包根目录
      __subpackage_shared__.js
      pages
        foo.js
        foo.wxml
        foo.json
        bar.js
        bar.wxml
        bar.json

Usage

$ yarn add taro-plugin-subpackage-optimize -D # npm i taro-plugin-subpackage-optimize  --save-dev

配置:

// config/index.js
const config = {
  // ...
  plugins: ['taro-plugin-subpackage-optimize'],
  // ...
}

支持的配置项:

| 配置项 | 默认值 | | | ----------- | ------ | ------------------------------------------------------------------------ | | enableInDev | false | 是否在 development 环境开启, 默认只在 production 环境开启 | | priority | 20 | 分包 cacheGroup 的优先级,默认是 20,即高于 Taro 默认的 vendor 和 common |

// config/index.js
const config = {
  // ...
  plugins: [
    [
      'taro-plugin-subpackage-optimize',
      {
        enableInDev: true,
      },
    ],
  ],
  // ...
}