主包大小超出2M,tabBar中包含了4个页面时如何通过分包减小主包的大小?

小程序 文章 2021-03-31 14:02 76 0 全屏看文

主包大小超出2M,tabBar中包含了4个页面时如何通过分包减小主包的大小?How to reduce the size of the main package by subcontracting when the size of the main package exceeds 2M and the tabBar contains 4 pages?

主包大小超出2M,tabBar中包含了4个页面时如何通过分包减小主包的大小?

在首次尝试预览功能时,我们发现代码包大小超出了上限2048kb。考虑到这个上限在正式发布小程序时仍然存在,我们决定通过分包解决此问题。

我们所包含的所有页面如下图所示:

其中,和tabBar相连的页面有Paunch, Rank, Notify以及Profile。

经过查找资料,我们了解到和tabBar相关的页面和小程序的首页必须放在主包内,其他页面可以被分出去。我们的页面结构如下图所示。

可以看到,根据上述原理,大部分页面还是必须存在于主包中,不能被分离出去。比如,若是我们将与tabBar相连的Punch页面分离出去,则会出现灰色部分的报错。报错出现的具体操作是将 app.json 中的

"pages": [    "pages/Login/index",    "pages/Punch/index",    "pages/Rank/index",    "pages/Notify/index",    "pages/Profile/index",    "pages/Register/index",    "pages/Change/index"


中的以下一行删去

"pages/Punch/index",


报错复制见下:

[ miniprogram/app.json 文件内容错误] miniprogram/app.json: ["tabBar"][0]["pagePath"]: "pages/Punch/index" need in ["pages"]



因此,主包中所包含的内容还是很多,主包大小还是很大。我们并不能通过分包将主包的大小减小到2048kb以下。

请问除了更改和tabBar绑定的页面和整体的UI逻辑,还有什么方法能解决我们现在的问题吗?或如果我们对以上概念有任何理解有误的地方,可否请您指出?谢谢!


When we tried the preview function for the first time, we found that the code package size exceeded the upper limit of 2048kb. Considering that the upper limit still exists when the applet is officially released, we decided to solve this problem through subcontracting. All the pages we include are shown in the figure below: the pages connected with tabbar include pause, rank, notify and profile. After searching for information, we learned that tabbar related pages and the front page of small programs must be placed in the main package, and other pages can be separated. Our page structure is shown in the figure below. As you can see, according to the above principle, most pages must still exist in the main package and cannot be separated. For example, if we separate the punch page connected to the tabbar, we will report an error in the gray part. The specific operation of error reporting is to app.json "Pages" in ["pages / login / index", "pages / punch / index", "pages / RANK / index", "pages / notify / index", "pages / profile / index", "pages / register / index", "pages / change / index", delete "pages / punch / index" from the following line, For error report copy, see the following: [miniprogram]/ app.json File content error] miniprogram/ app.json : ["tabbar"] [0] ["pagepath"]: "pages / punch / index" need in ["pages"]. Therefore, the main package contains a lot of content and the size of the main package is still very large. We can't reduce the size of the main packet to less than 2048kb by subcontracting. Apart from changing the page bound to the tabbar and the overall UI logic, is there any way to solve our current problem? Or if we have any misunderstanding about the above concepts, could you please point out? thank you!

回答:

Made in.内江:

把你的zip文件删掉。

Brother斌🎈:

7个页面6M 怎么厉害

Samuel.Schödinger:
想分包的tabBar页做个跳转就好,把tabBar页东西挪到分包,然后tabBar页现在一进去就跳转到分包
贝荣琪Roxanne ツ:谢谢您提供的思路!请问是需要自定义tabBar嘛?

-EOF-