Fix uniapp Mini Program vendor.js Too Large
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": { |
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
- Focus first on sub-packaging—this gives the biggest reduction.
- Avoid importing heavy libraries in global scope when only needed in a few pages.
- Periodically inspect build artifacts to catch growth early.
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Comments