自学内容网 自学内容网

微信小程序-独立分包/分包预下载

一.独立分包

独立分包不依赖主包运行。
在subPackages添加Independent字段,声明独立分包
独立分包不能使用主包和其它包资源。
代码:

  "subPackages": [
    {
      "root": "modules/marketModule",
      "name": "marketModule",
      "pages": [
        "pages/market/market"
      ],
      "independent": true 
    }
  ]

二.预加载分包

在访问页面的时候就先加载其它分包或者主包的代码和资源,可以直接使用。
在app.json里面使用preloadRule字段预置下载规则

  "preloadRule": {
    "pages/index/index":{
      "network": "all",
      "packages": ["modules/marketModule"] //分包名或者路径
    },
    "modules/marketModule/pages/market/market":{
      "network": "all",
      "packages": ["__APP__"]
    }
  }

原文地址:https://blog.csdn.net/weixin_42284031/article/details/142964789

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!