原生小程序分包和 uniapp 小程序分包差不多。
分包只是在原有代码结构上,指定那个文件夹属于分包,所以,页面地址原本路径不会修改。
比如,将pages/mine
设为分包,mine下面的有页面地址pages/mine/index/index
,分包后仍为pages/mine/index/index
这种。
- 目前并不限制分包的数量
- 整个小程序所有分包大小不超过 20M
- 单个分包/主包大小不能超过 2M
参考文档:https://developers.weixin.qq.com/miniprogram/dev/framework/subpackages/basic.html
原生:修改app.json
uniapp:修改pages.json
以原生小程序举例:
在app.json 中,与pages对象同级,配置subpackages,配置项如文档:
项目的文件结构如下:
假如,我要将pages下面的mine设为分包,app.json中subpackages应为:
{
"pages": [
"pages/index/index",
//出现在subPackages 里面的路径不可在pages中出现,
// "pages/mine/infomation/infomation",
//"pages/mine/selfIntro/selfIntro",
//"pages/mine/interest/interest",
// "pages/mine/phone/phone",
// "pages/mine/verification/verification",
//"pages/mine/cityList/cityList",
// "pages/mine/photoWall/photoWall",
],
"subPackages": [
{
"root": "pages/mine",//分包根目录地址
"pages": [
"cityList/cityList",//路径相对地址
"infomation/infomation",
"interest/interest",
"..."
]
}
]
}
在uniapp中写法如下:
{
"pages": [
"pages/index/index",
//出现在subPackages 里面的路径不可在pages中出现,
// "pages/mine/infomation/infomation",
//"pages/mine/selfIntro/selfIntro",
//"pages/mine/interest/interest",
// "pages/mine/phone/phone",
// "pages/mine/verification/verification",
//"pages/mine/cityList/cityList",
// "pages/mine/photoWall/photoWall",
],
"subPackages": [
{
"root": "pages/mine",//分包根目录地址
"pages": [
{"path":"cityList/cityList"},
{"path":"infomation/infomation"},
{"path":"interest/interest"},
{...}
]
}
]
}
假如在uniapp中,分包之后,代码包还是比较大,可以采用压缩。如下图,勾选即可。