小程序的包体积限制是2M,超出包大小如何优化
先简单列出,最近比较忙,后续优化明细,有着急的先留言踢我
1.分包
留几个主要的页面体积小的,剩下的在page.json中拆到subpackages中,简单举个例子
"pages": [ //pages数组中第一项表示应用启动页,参考https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/home/index",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": true
}
},
{
"path": "pages/shoppingCart/index",
"style": {
"navigationBarTitleText": "购物车",
"enablePullDownRefresh": true
}
},
{
"path": "pages/user/index",
"style": {
"navigationBarTitleText": "我的"
}
},
],
"subpackages": [
// 订单相关
{
"root": "pages/order",
"pages": [
{
"path": "index",
"style": {
"navigationBarTitleText": "订单"
}
},
{
"path": "refund",
"style": {
"navigationBarTitleText": "申请退款"
}
},
{
"path": "drugs/detail",
"style": {
"navigationBarTitleText": "订单详情"
}
},
{
"path": "afterSale",
"style": {
"navigationBarTitleText": "查看售后"
}
},
{
"path": "consultation/detail",
"style": {
"navigationBarTitleText": "订单详情"
}
},
{
"path": "servicePack/detail",
"style": {
"navigationBarTitleText": "订单详情"
}
},
{
"path": "drugsAfter/chooseType",
"style": {
"navigationBarTitleText": "选择售后类型"
}
},
{
"path": "drugsAfter/chooseShop",
"style": {
"navigationBarTitleText": "选择售后货物"
}
},
{
"path": "drugsAfter/submitRefund",
"style": {
"navigationBarTitleText": "提交售后"
}
},
{
"path": "drugsAfter/trackNumber",
"style": {
"navigationBarTitleText": "填写快递单号"
}
},
{
"path": "drugsAfter/afterInfo",
"style": {
"navigationBarTitleText": "售后详情"
}
},
{
"path": "drugsAfter/negotiationRecord",
"style": {
"navigationBarTitleText": "协商记录"
}
}
]
},
],
2.图片放到服务器
将图片放到服务器当中,应当同步所有环境,并且最好自己再备份一个文件夹存储图片,用于服务器出现问题时,图片不会丢失,先去忙了后续更新...
3.大功能需求内嵌H5(但分享会收到影响)
4.代码压缩设置
5.删除多余代码