小程序分包功能

分包其实很简单,一开始我把他想的很复杂,导致我浪费了半天时间......

其实分包实质上就是目录结构改变下,然后app.json的配置改变下,

tabbar页面单独放一个包,结构如下

小程序分包功能_第1张图片

{
"pages": [ //pages不能没有(如果报错请把注释删掉)
"page/tabBar/index/index",
"page/tabBar/warehouse/index",
"page/tabBar/mycenter/index"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "分包演示",
"navigationBarTextStyle": "black"
},
"tabBar": {
"color": "#2e2e2e",
"selectedColor": "#db4b29",
"backgroundColor": "#FFFFFF",
"borderStyle": "#D0D1D3",
"fontSize": "22rpx",
"list": [
{
"pagePath": "page/tabBar/xxx/xxx",
"text": "首页",
"iconPath": "./res/home.png",
"selectedIconPath": "./res/a_home.png"
},
{
"pagePath": "page/tabBar/xxx/xxx",
"text": "茶仓",
"iconPath": "./res/cy.png",
"selectedIconPath": "./res/a_cy.png"
},
{
"pagePath": "page/tabBar/xxx/xxx",
"text": "我的",
"iconPath": "./res/my.png",
"selectedIconPath": "./res/a_my.png"
}
]
},
"subPackages": [
{
"root": "page/teaindex/",
"pages": [
"pages/xxx/xxx"
]
},
{
"root": "page/warehouse/",
"pages": [
"pages/xxx/xxx",
]
},
{
"root": "page/center/",
"pages": [
"pages/xxx/xxx"
]
}
]
}

分包的好处有很多,无论是加载速度还是体积大小都有不小的提升!'有什么疑问可以在评论区留言,

你可能感兴趣的:(小程序分包功能)