当前位置:网站首页>uniapp小程序 subPackages分包配置
uniapp小程序 subPackages分包配置
2022-07-02 10:16:00 【老张在线敲代码】
使用场景:
uniapp开发各种小程序时候遇到主包过大,无法上传的情况
在开发者工具中有一个选项用于测试时候使用,可以提高分包大小
分包机制
小程序启动时,默认会下载主包并启动主包内页面,当用户进入分包内某个页面时,会把对应分包自动下载下来,下载完成后再进行展示。
每个使用分包小程序必定含有一个主包。所谓的主包,即放置默认启动页面/TabBar 页面,以及一些所有分包都需用到公共资源/JS脚本;而分包则是根据开发者的配置进行划分。
目前小程序分包大小有以下限制:
整个小程序所有分包大小不超过 20M
单个分包/主包大小不能超过 2M
对小程序进行分包,可以优化小程序首次启动的下载时间,以及在多团队共同开发时可以更好的解耦协作。
分包下支持独立的 文件 目录,用来对静态资源进行分包。

这个是正常组件目录
1.首先,在uniapp结构里原本已经有一个pages的包(文件夹)了,这时候在pages同级里新建一个subpkg(commission)包 并新建页面
2.配置pages.json(原生小程序则需要去app.json配置)
在pages.json中新建数组"subPackages",数组中包含两个参数:1.root:为子包的根目录,2.pages:子包由哪些页面组成,参数同pages;
"subpackages": [
{
"root": "commission/",
"pages": [
{
"path" : "pages/index",
"style" :
{
"navigationBarTitleText": "我的收益",
"enablePullDownRefresh": false
}
},{
"path" : "pages/poster/index",
"style" :
{
"navigationBarTitleText": "邀请好友",
"enablePullDownRefresh": false
}
},{
"path" : "pages/down/index",
"style" :
{
"navigationBarTitleText": "好友列表",
"enablePullDownRefresh": false
}
},{
"path" : "pages/count/index",
"style" :
{
"navigationBarTitleText": "数据统计",
"navigationStyle": "custom" ,
"enablePullDownRefresh": false
}
}
]
}
],
注意:主包和分包是不能再同一目录下,在构建uniapp项目时,可以考虑一下目录结构,以便后期进行分包;
3.分包预载配置(preloadRule)
主要为了优化速度,不想优化速度的可以跳过这个配置
配置preloadRule后,在进入小程序某个页面时,由框架自动预下载可能需要的分包,提升进入后续分包页面时的启动速度
preloadRule 中,key 是页面路径,value 是进入此页面的预下载配置,每个配置有以下几项:

边栏推荐
- What are eNB, EPC and PGW?
- Explanation of 34 common terms on the Internet
- Pointer from entry to advanced (1)
- Winter vacation daily question - lucky numbers in the matrix
- 研究表明“气味相投”更易成为朋友
- 最近公共祖先LCA的三种求法
- (POJ - 1308)Is It A Tree? (tree)
- [Blue Bridge Cup] children's worship circle
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
- 无向图的桥
猜你喜欢

A better database client management tool than Navicat

Why is the default of switch followed by break?

Find love for speed in F1 delta time Grand Prix

Integral link, inertia link and proportion link in Simulink

Unity skframework framework (XX), VFX lab special effects library

Unity skframework framework (XIII), question module

Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm

Unity skframework framework (XVI), package manager development kit Manager
![Unity small map production [2]](/img/d6/9d6556d37525b9986b74133f2a7aaa.jpg)
Unity small map production [2]
![[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials](/img/42/21f6d0fdd159faa8b63713624c95a2.png)
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
随机推荐
Unity SKFramework框架(十二)、Score 计分模块
[unity] using GB2312, the solution to abnormal program after packaging
OpenFOAM:lduMatrix&lduAddressing
每日一题:1175.质数排列
Gee learning notes 2
Integral link, inertia link and proportion link in Simulink
Performance optimization of memory function
JS reverse massive creative signature
What are eNB, EPC and PGW?
Fundamentals of machine learning (II) -- division of training set and test set
大家信夫一站式信用平台让信用场景“用起来
Security RememberMe原理分析
二、帧模式 MPLS 操作
题解《子数整数》、《欢乐地跳》、《开灯》
Mysql常用命令详细大全
Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
Unity SKFramework框架(十三)、Question 问题模块
Three methods of finding LCA of the nearest common ancestor
[Unity]使用GB2312,打包后程序不正常解决方案
Answer: can the audio be set to on by default during easydss video on demand?

