Problem

Project had 147 pages. The compiled vendor.js reached 2.4 MB. WeChat Mini Program build then failed to convert to ES5 correctly; downloaded source maps degraded to lines of ;;;;;, making production error stack tracing impossible.

Step 1. Subpackage Non‑Core Pages

Split non‑core pages using uni-app subpackages so only main package code is bundled into vendor.js.
Docs: https://uniapp.dcloud.io/collocation/pages?id=subpackages

manifest.json (enable automatic subpackage optimization for WeChat Mini Program):

"mp-weixin": {
"optimization": {
"subPackages": true
}
}

Step 2. Secondary Compression

After sub-packaging, run the generated vendor.js through an extra minification pass (e.g. https://jscompress.com or terser) to squeeze a few more KB.

Result

vendor.js shrank to about 160 KB and ES5 conversion succeeded; source maps became readable again.

Notes

  1. Focus first on sub-packaging—this gives the biggest reduction.
  2. Avoid importing heavy libraries in global scope when only needed in a few pages.
  3. Periodically inspect build artifacts to catch growth early.