微信小程序> 微信小程序代码分包及优化

微信小程序代码分包及优化

浏览量:447 时间: 来源:康__

前提:微信小程序上传代码时报错显示不能超过2M
没有分包前,app.json的配置代码如下:

    {  "pages": [    "pages/index/index",    "pages/index/scanCode/scanCode",    "pages/index/shopListScan/shopListScan",    "pages/index/shopDetail/shopDetail",    "pages/index/payScan/payScan",    "pages/index/payFinish/payFinish",    "pages/logs/logs",    "pages/login/login",    "pages/person/person",    "pages/person/identify",    "pages/biddingHall/biddingHall",    "pages/transport/transCenter",    "pages/transport/transList",    "pages/transport/transDetail",    "pages/biddingHall/bidPrice",    "pages/grab/grab",    "pages/grab/grabDetail",    "pages/person/setList",    "pages/person/setSafe",    "pages/person/modifyPwd",    "pages/person/msgMan",    "pages/person/feedback",    "pages/person/balance/balance",    "pages/person/myCar/myCar",    "pages/person/supplier/supplier",    "pages/person/supplier/supplierAdd",    "pages/person/payPwd/payPwd",    "pages/person/cardPwd/cardPwd",    "pages/person/bank/bankBind",    "pages/person/bank/cash",    "pages/person/myCar/carDetail",    "pages/person/myCar/carAdd",    "pages/person/card/card",    "pages/person/card/cardApply",    "pages/person/bill/receive",    "pages/person/bill/billDetail",    "pages/person/card/masterSub/masterSub",    "pages/person/personDetail/personDetail",    "pages/taskHall/taskHall",    "pages/taskHall/taskOrder",    "pages/components/selector/selector",    "pages/transport/unusual/unusualReply",    "pages/tabBar/tabTubang/tabTubang",    "pages/tabBar/tabTrends/tabTrends",    "pages/shop/index/index",    "pages/shop/insurance/insureList",    "pages/myCar/myCar",    "utils/request/address/address"  ],  "window": {    "backgroundTextStyle": "light",    "navigationBarBackgroundColor": "#fff",    "navigationBarTitleText": "途邦",    "navigationBarTextStyle": "black"  },  "sitemapLocation": "sitemap.json",  "permission": {    "scope.userLocation": {      "desc": "你的位置信息将用于小程序位置接口的效果展示"    }  },  "tabBar": {    "color": "#c3c6c9",    "selectedColor": "#00a5fe",    "borderStyle": "black",    "list": [      {        "iconPath": "/pages/index/images/tab1.png",        "selectedIconPath": "/pages/index/images/tab1s.png",        "pagePath": "pages/index/index",        "text": "智运"      },      {        "iconPath": "/pages/index/images/tab2.png",        "selectedIconPath": "/pages/index/images/tab2s.png",        "pagePath": "pages/tabBar/tabTubang/tabTubang",        "text": "途邦"      },      {        "iconPath": "/pages/index/images/tab3.png",        "selectedIconPath": "/pages/index/images/tab3s.png",        "pagePath": "pages/tabBar/tabTrends/tabTrends",        "text": "动态"      },      {        "iconPath": "/pages/index/images/tab4.png",        "selectedIconPath": "/pages/index/images/tab4s.png",        "pagePath": "pages/person/person",        "text": "我的"      }    ]  }}

之后在微信官网找到解决办法,目前分包后单个包不能超过2M,项目总文件不能超过8M
微信官网-分包
参考后配置app.json如下:

{"pages": ["pages/index/index","pages/index/scanCode/scanCode","pages/index/shopListScan/shopListScan","pages/index/shopDetail/shopDetail","pages/index/payScan/payScan","pages/index/payFinish/payFinish","pages/logs/logs","pages/login/login","pages/components/selector/selector","pages/tabBar/tabTubang/tabTubang","pages/tabBar/tabTrends/tabTrends","pages/person/person","pages/person/setList","pages/person/setSafe","pages/person/modifyPwd","pages/person/msgMan","pages/person/feedback","pages/person/identify","pages/person/bank/bank/bankBind","pages/person/bank/bank/cash"],"subPackages":[{"root":"pages/person/address","pages":[    "address",    "addrList/addrList",    "addrAdd/addrAdd",    "addrDetail/addrDetail"    ]},{"root":"pages/person/payPwd","pages": [    "payPwd"    ]},{"root":"pages/person/cardPwd","pages": [    "cardPwd"    ]},{"root":"pages/person/personDetail","pages": [    "personDetail"    ]},{"root": "pages/person/card","pages": ["card","cardApply","masterSub/masterSub"]},{"root":"pages/person/myCar","pages": [    "carDetail",    "carAdd",    "myCar"   ]},{"root":"pages/person/bill","pages": [    "receive",    "billDetail"    ]},{"root":"pages/person/balance","pages": [    "balance"    ]},{"root":"pages/person/supplier","pages": [    "supplier",    "supplierAdd"    ]},{"root":"pages/shop","pages": [    "index/index",    "insurance/insureList"    ]},{"root":"pages/transport","pages": [    "transCenter",    "transList",    "transDetail",    "unusual/unusualReply"    ]},{"root":"pages/biddingHall","pages": [    "biddingHall",    "bidPrice"    ]},{"root":"pages/taskHall","pages": [    "taskHall",    "taskOrder"    ]},{"root":"pages/grab","pages": [    "grab",    "grabDetail"    ]}],"window": {"backgroundTextStyle": "light","navigationBarBackgroundColor": "#fff","navigationBarTitleText": "xx","navigationBarTextStyle": "black"},"sitemapLocation": "sitemap.json","permission": {"scope.userLocation": {"desc": "你的位置信息将用于小程序位置接口的效果展示"}},"tabBar": {"color": "#c3c6c9","selectedColor": "#00a5fe","borderStyle": "black","list": [{"iconPath": "/pages/index/images/tab1.png","selectedIconPath": "/pages/index/images/tab1s.png","pagePath": "pages/index/index","text": "智运"},{"iconPath": "/pages/index/images/tab2.png","selectedIconPath": "/pages/index/images/tab2s.png","pagePath": "pages/tabBar/tabTubang/tabTubang","text": "xx"},{"iconPath": "/pages/index/images/tab3.png","selectedIconPath": "/pages/index/images/tab3s.png","pagePath": "pages/tabBar/tabTrends/tabTrends","text": "动态"},{"iconPath": "/pages/index/images/tab4.png","selectedIconPath": "/pages/index/images/tab4s.png","pagePath": "pages/person/person","text": "我的"}]}}

在配置过程中有很多关联的.wxss和.js文件,所以会报错无法加载页面,我的解决办法是将这些提到根目录的common文件中(公共文件)
小程序

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎