I. Small program subcontracting

Each subcontracting applet must contain a main package. The main package, which places the default startup page /TabBar page, and some common resource /JS scripts for all the subpackages; Subcontracting is divided according to the developer’s configuration.

When the small program starts, the main package will be downloaded and the page in the main package will be started by default. When the user enters a page in the subpackage, the client will download the corresponding subpackage and display it after downloading

Currently, the subcontracting size of small program has the following limitations:

The size of all subcontracts for the whole small program shall not exceed 20M. The size of single subcontract/main package shall not exceed 2M. Subcontracting the small program can optimize the download time of the first startup of the small program and better decouples cooperation in the joint development of multiple teams.

Click here directly to see the official subcontracting tutorial easy to understand:

Developers.weixin.qq.com/miniprogram…

Ii. Uniapp subcontracting applets

App defaults to a whole package. Subcontracting configuration compatible with applets. It is not intended for download acceleration, but for startup acceleration when the home page is vUE.

  • Components: Common components (referenced by the main package)
  • Page_ followed by pinyin are subcontracting
  • Components in a subcontract are the subcontract’s own component directory. References to the subcontract’s vue page can only be referenced in the subcontract’s own page_XXXX directory
  • Pages is the main package, which contains the launch page /TabBar page
  • Static is a public static resource, an image class

Subcontracting steps:

1. Configure the manifest. Json

“mp-weixin”: {

“optimization”:{“subPackages”:true}

}

Optimize subcontracting:

Add “optimization”:{“subPackages”:true} under the platform configuration (manifest.json) to enable subPackages

Currently, subcontracting optimization of MP-Weixin, MP-QQ and MP-Baidu is only supported

  • Static files: Under subcontracting, static resources such as static resources are copied. That is, static resources placed in subcontracting directories are not packaged into the main package and cannot be used in the main package
  • Js file: When a JS is referenced by only one subpackage, it will be packaged into that subpackage, otherwise it will still be shipped to the main package (i.e. referenced by the main package, or referenced by more than one subpackage).
  • Custom component: If a custom component is referenced by only one subcontract and is not included in the subcontract, a message will be displayed at compile time

2. Configuration pages. Json

Json file containing two parameters: 1. Root: indicates the root directory of the subPackages. 2.

Note: The main package and subcontracting cannot be in the same directory. When building the UNIAPP project, we can consider the directory structure for later subcontracting.

3. PreloadRule

This step is mainly done to optimize speed, those who do not want to optimize speed can skip this configuration

After preloadRule is configured, when entering a certain page of the mini program, the framework automatically preloads the subcontracting that may be needed, which improves the startup speed when entering the subsequent subcontracting page

In preloadRule, key is the path to the page, and value is the pre-downloaded configuration to enter the page. Each configuration has the following items:

field type mandatory The default value instructions
packages StringArray is There is no Enter the page after the pre-download subcontractedroot 或 name.__APP__Represents the primary package.
network String no wifi For pre-download on a specified network, the options are as follows: all (unlimited network), wifi (pre-download on wifi only)

App subcontracting also supports preloadRule, but network rules are not valid.

You can view the official configuration items:

Uniapp. Dcloud. IO/collocation…