当前位置:网站首页>Subcontracting of wechat applet based on uni app

Subcontracting of wechat applet based on uni app

2022-04-23 21:23:00 Sister Chunfeng

About subcontracting

The specified applet cannot exceed 2M, Once exceeded, subcontracting is required

matters needing attention

subPackages Inside pages The path is root Next relative path , Not a full path .
The size of each package of wechat applet is 2M, The total volume cannot exceed 16M.
The size of each subcontract of Baidu applet is 2M, The total volume cannot exceed 8M.
The size of each subpackage of Alipay applet is 2M, The total volume cannot exceed 4M.
QQ The size of each package of the applet is 2M, The total volume cannot exceed 24M.
Independent services are supported under subcontracting static Catalog , Used to subcontract static resources .
uni-app Support for wechat applet 、QQ Applet 、 Baidu applet subcontracting optimization , About static resources or js The file is put into the subcontract and does not occupy the size of the main package . Please refer to : Description of subcontract optimization
in the light of vendor.js If it is too large, you can use runtime compression code
HBuilderX Check run... For the created item –> Run to the applet Simulator –> Whether the runtime compresses the code
cli The project created can be in pacakge.json Add parameters in –minimize, Example :“dev:mp-weixin”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch --minimize”

Usage method

First you have to have one uniapp Wechat applet project of

Let's say you have , Original project structure
 Insert picture description here
Open it with wechat development tool , Before subcontracting
 Insert picture description here

stay pages Create subcontracting at the same level

 Insert picture description here
pages.json To configure
 Insert picture description here
so what , The official website supports it Subcontract optimization
Add... Under the configuration of the corresponding platform "optimization":{“subPackages”:true} Turn on subcontracting optimization
Currently only supported mp-weixin、mp-qq、mp-baidu Optimization of subcontracting
Specific logic of subcontract optimization :
Static files : Subcontract support static And other static resource copies , That is, static resources placed in the subcontract directory will not be packaged into the main package , It can't be used in the main package
js file : When a js When referenced by only one subcontract , The js Will be packed into the subcontract , Otherwise, it still hits the main package ( It is referenced by the main package , Or be surpassed 1 Subcontracting references )
Custom components : If a custom component is referenced by only one subcontract , And not put into the subcontract , Compile time will output prompt information
My understanding is that , Now that you subcontract the function modules , You can score the corresponding static resources , When using pictures, it is directly the path under subcontracting , This is a complete subcontracting .

Here I take wechat applet as an example ,
 Insert picture description here
 Insert picture description here

How to jump ?

Just click where you need to jump

 uni.navigateTo({
    
   url: '/myPackageA/pages/piece/piece'
 })

Then restart the wechat development tool to run
 Insert picture description here
You can see that the subcontracting has been successful

版权声明
本文为[Sister Chunfeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/110/202204200620164308.html