微信小程序分包加载设置

设置分包加载

微信小程序分包限制为:

  • 主包或者单个分包最大为2M
  • 整体小程序所有包最大为8M
为什么需要设置分包?
  1. 小程序项目中,有多种角色(公共页面很少),设置分包加载方便管理
  2. 整个小程序压缩后代码大小超过2M,只能将小程序哈芬为不同的包
  3. 分包加载,在小程序启动时,默认下载主包并启动主包内的页面,当用户进入某个分包时,将对应的分包下载并启动,优化小程序首次启动的下载时间。

分包设置格式如下实例代码:

  "pages": [
    "loading/loading"      //主包
  ],
  "subpackages": [
    {
      "root": "procurement",  //分包名称
      "pages": [   //分包内的页面(路径)
        "index/index",
        "myPassCard/myPassCard",
        "apply/apply",
        "usable/usable",
        "unauthorized/unauthorized",
        "authdriver/authdriver",
        "applicationdetails/applicationdetails",
        "rejectdetail/rejectdetail",
        "createInvitecode/createInvitecode"
      ]
    },
    {
      "root": "driver",
      "pages": [
        "index/index",
        "driverPassCard/driverPassCard",
        "useable/useable",
        "unauthorized/unauthorized",
        "applicationdetails/applicationdetails",
        "rejectdetail/rejectdetail",
        "apply/apply",
        "changeWay/changeWay"
      ]
    },
    {
      "root": "rural",
      "pages": [
        "index/index",
        "ruralPassCard/ruralPassCard",
        "stayconfirm/stayconfirm",
        "useable/useable",
        "changeGoods/changeGoods",
        "loadconfirm/loadconfirm",
        "writeLoadInfo/writeLoadInfo"
      ]
    },
    {
      "root": "station",
      "pages": [
        "index/index",
        "carList/carList",
        "scan/scan",
        "carListDetail/carListDetail"
      ]
    },
    {
      "root": "GaoGuanju",
      "pages": [
        "index/index",
        "myPassCard/myPassCard",
        "useable/useable",
        "audit/audit",
        "rejected/rejected",
        "chart/chart",
        "credit/credit",
        "creditDetail/creditDetail",
        "scan/scan"
      ]
    },
    {
      "root": "pages",
      "pages": [
        "login/login",
        "forgetpassword/forgetpassword",
        "register/register",
        "setting/setting",
        "qrCode/qrCode",
        "message/message",
        "historycredent/historycredent",
        "resetPass/resetPass",
        "search/search",
        "historydetail/historydetail",
        "credentialUsed/credentialUsed",
        "about/about",
        "addGoods/addGoods",
        "deal/deal",
        "messageDetail/messageDetail"
      ]
    }
  ],

你可能感兴趣的:(小程序,微信小程序分包加载)