微信小程序拆包
微信小程序本身打包体积有 2M 的限制。微信官方提供了小程序分包的方法,主包和分包每个不能超过 2M,加一起不能超过 8M。
具体方法:
json
{
"pages": [
"pages/newIndex/index",
"pages/news/index",
"pages/index/index",
"pages/my/my",
"pages/index/search/index",
"pages/index/searchMore/index",
"pages/index/searchParts/index",
"pages/index/searchMinifigs/index",
"pages/index/searchClassify/index",
"pages/index/set/index",
"pages/index/bannerDetail/bannerDetail",
"pages/index/set/setDetail/index",
"pages/index/set/partMinifigs/index",
"pages/index/set/partMinifigsDetail/index",
"pages/index/set/bigPartsDetail/index",
"pages/index/set/shop/index",
"pages/my/myHistoryCollect/index",
"pages/login/telphone/telphone",
"pages/picture/detail/index",
"pages/activity/bill/index/index"
]
}
以上是旧的版本,可以看到页面非常多,所有页面都是pages下面,最终打包出来的体积也非常大。
经过优化,我们把非入口页面 移到 单独目录packageSub下
json
{
"pages": [
"pages/newIndex/index",
"pages/index/index",
"pages/my/my",
"pages/login/login",
"pages/login/telphone/telphone",
"pages/activity/bill/index/index"
],
"subPackages": [
{
"root": "packageSub",
"pages": [
"shop/index",
"shop/shopDetail/index",
"shop/shopCar/index",
"shop/payPage/index",
"shop/remark/index",
"shop/rate/index",
"community/index",
"community/sendCommunity/index",
"community/sendComment/index",
"community/detail/index",
"my/myHistoryCollect/index",
"news/index",
"offline/offline"
]
}
]
}
文件目录页面变化:
注意 别忘了修改老的 wx.navigateTo 方法的路径
旧的 新的