跪拜 Guibai
← All articles
Frontend

AI Built the Game, WeChat Rejected It: Cocos Subpackage Setup for the 4 MB Limit

By 亿元程序员 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

A Cocos WeChat mini game that crosses the 4 MB main-package ceiling cannot be uploaded until the build is split. Subpackage and remote Bundle configuration are the standard fixes, and neither changes total asset size.

Summary

WeChat mini games have a hard upload constraint: the main package must stay within 4 MB. One AI-assisted Cocos project had a main package of 4.02 MB and was rejected at upload. Moving it into subpackages does not shrink the game; the build splits into a main package plus subpackages, total size stays the same, and the startup package fits the limit.

Cocos Creator handles this through Asset Bundles. The built-in resources folder is already a Bundle and cannot be unmarked. Any other folder can be configured as a Bundle and then assigned as a WeChat subpackage in the build settings. After export, the build contains a main package and a subpackage, and the upload goes through.

Games that outgrow even the subpackage scheme can move Bundles to a server. A folder marked as a Bundle and built separately can be loaded at runtime with assetManager.loadBundle('https://...'), then a scene starts through bundle.loadScene and director.runScene. Asset optimization belongs before subpackaging; that topic is left aside.

Takeaways
— WeChat mini game uploads reject a main package over 4 MB; 4.02 MB was enough to fail.
— The resources folder in Cocos Creator is a built-in Bundle and cannot be unmarked.
— Any other folder can be marked as a Bundle; Bundle folders can be assigned as subpackages in the build panel.
— After a subpackage export, the output is a main package plus a subpackage, and total size stays the same.
— Larger games can build a Bundle to a server and load it at runtime with assetManager.loadBundle, followed by bundle.loadScene and director.runScene.
— Asset optimization is recommended before subpackaging, but the technique is not covered.
Conclusions

Subpackaging keeps total size unchanged; it only moves bytes out of the initial download, so the 4 MB rule governs startup payload, not game size.

AI-assisted development does not exempt a project from platform packaging rules; a game generated with AI still needs build configuration such as Bundle markers and subpackage assignment before it can ship.

Concepts & terms
WeChat Mini Game subpackage
A build-time split that keeps the main package under WeChat's 4 MB limit. The main package downloads first; subpackages load later on demand, so the total game can be larger than the main-package cap.
Asset Bundle (AB)
A Cocos Creator folder marked as an independent, loadable unit. Bundles can be packaged as WeChat subpackages or hosted on a server and fetched at runtime with assetManager.loadBundle.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗