search
HomeWeb Front-enduni-appTeach you step by step how to subcontract uniapp and mini programs (pictures and text)

This article brings you relevant knowledge about uniapp cross-domain, which introduces the issues related to subcontracting of uniapp and mini programs. Each mini program that uses subcontracting must contain a main package. . The so-called main package is where the default startup page/TabBar page is placed, and some public resources/JS scripts are required for all sub-packages; while sub-packages are divided according to the developer's configuration. I hope it will be helpful to everyone.

Teach you step by step how to subcontract uniapp and mini programs (pictures and text)

Recommended: "uniapp tutorial"

1. Mini program sub-packaging

Each use sub-packaging The applet must contain a main package. The so-called main package is where the default startup page/TabBar page is placed, and some public resources/JS scripts are required for all sub-packages; and sub-packages are divided according to the developer's configuration.

When the mini program is started, the main package will be downloaded by default and the page in the main package will be launched. When the user enters a page in the sub-package, the client will download the corresponding sub-package and proceed after the download is completed. Display

Currently, the sub-package size of the mini program has the following restrictions:

  • The size of all sub-packages of the entire mini program does not exceed 20M
  • The size of a single sub-package/main package cannot More than 2M

Subcontracting the mini program can optimize the download time for the first startup of the mini program, and enable better decoupling and collaboration when multiple teams develop together.

Click here directly to see the official subcontracting tutorial, which is easy to understand

2. Uniapp subcontracting applet

App defaults to the entire package. Compatible with subcontracting configuration of mini programs. Its purpose is not to speed up downloads, but to speed up startup when the homepage is vue.

This is the directory structure after I subcontract the applet

  • components: public components (for reference by the main package)
  • page_followed by pinyin are all sub-packages
  • The components in a sub-package are the component directories of a single sub-package. The reference of the sub-package vue page can only be referenced in its own page_zhaoshang sub-contract directory
  • pages is the main package, which contains the startup page/TabBar page
  • static contains public static resources, and the picture class

Subcontracting steps:

1. Configure manifest.json

"mp-weixin": {

"optimization":{"subPackages":true}

}

Optimize subcontracting:

In the configuration of the corresponding platform (manifest. json), add "optimization":{"subPackages":true}Enable subpackage optimization

Currently only supports mp-weixin, mp-qq , mp-baidu's subcontracting optimization

  • Static files: support copying of static resources such as static under subcontracting, that is, static resources placed in the subcontracting directory will not Be packaged into the main package, and
  • js files cannot be used in the main package: When a js is only referenced by one sub-package, the js will be packaged into the sub-package, otherwise it will still be hit. Main package (i.e. referenced by the main package, or referenced by more than 1 sub-package)
  • Custom component: If a custom component is only referenced by one sub-package and is not placed in the sub-package , a prompt message will be output when compiling

2. Configure pages.json

Create a new array "subPackages" in pages.json. The array contains two parameters: 1.root: is the root directory of the sub-package, 2.pages: which pages the sub-package consists of, the parameters are the same as pages;

Note: the main package and sub-package cannot be in the same directory, when building the uniapp project , you can consider the directory structure for later subcontracting;

3. Subcontracting preload configuration (preloadRule)

Do this step Mainly for optimizing speed, if you don’t want to optimize speed, you can skip this configuration

After configuring preloadRule, when entering a certain page of the mini program, the framework will automatically pre-download the sub-packaging that may be required, and then enter the subsequent sub-packaging page. In

preloadRule, key is the page path, value is the pre-download configuration to enter this page, each configuration has The following items:

Field Type Required Default value Description
packages StringArray Yes None Preset after entering the page Download the subpackaged root or name. __APP__ represents the main package.
network String No wifi Pre-download under the specified network, optional value For: all (not limited to network), wifi (only pre-downloaded under wifi)

App subcontracting also supports preloadRule, but the network rules are invalid.

Example:

Finally click to enter the uniapp official document to view the configuration items

Recommendation: "uniapp tutorial"

The above is the detailed content of Teach you step by step how to subcontract uniapp and mini programs (pictures and text). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:脚本之家. If there is any infringement, please contact admin@php.cn delete
How do you debug issues on different platforms (e.g., mobile, web)?How do you debug issues on different platforms (e.g., mobile, web)?Mar 27, 2025 pm 05:07 PM

The article discusses debugging strategies for mobile and web platforms, highlighting tools like Android Studio, Xcode, and Chrome DevTools, and techniques for consistent results across OS and performance optimization.

What debugging tools are available for UniApp development?What debugging tools are available for UniApp development?Mar 27, 2025 pm 05:05 PM

The article discusses debugging tools and best practices for UniApp development, focusing on tools like HBuilderX, WeChat Developer Tools, and Chrome DevTools.

How do you perform end-to-end testing for UniApp applications?How do you perform end-to-end testing for UniApp applications?Mar 27, 2025 pm 05:04 PM

The article discusses end-to-end testing for UniApp applications across multiple platforms. It covers defining test scenarios, choosing tools like Appium and Cypress, setting up environments, writing and running tests, analyzing results, and integrat

What are the different types of testing that you can perform in a UniApp application?What are the different types of testing that you can perform in a UniApp application?Mar 27, 2025 pm 04:59 PM

The article discusses various testing types for UniApp applications, including unit, integration, functional, UI/UX, performance, cross-platform, and security testing. It also covers ensuring cross-platform compatibility and recommends tools like Jes

What are some common performance anti-patterns in UniApp?What are some common performance anti-patterns in UniApp?Mar 27, 2025 pm 04:58 PM

The article discusses common performance anti-patterns in UniApp development, such as excessive global data use and inefficient data binding, and offers strategies to identify and mitigate these issues for better app performance.

How can you use profiling tools to identify performance bottlenecks in UniApp?How can you use profiling tools to identify performance bottlenecks in UniApp?Mar 27, 2025 pm 04:57 PM

The article discusses using profiling tools to identify and resolve performance bottlenecks in UniApp, focusing on setup, data analysis, and optimization.

How can you optimize network requests in UniApp?How can you optimize network requests in UniApp?Mar 27, 2025 pm 04:52 PM

The article discusses strategies for optimizing network requests in UniApp, focusing on reducing latency, implementing caching, and using monitoring tools to enhance application performance.

How can you optimize images for web performance in UniApp?How can you optimize images for web performance in UniApp?Mar 27, 2025 pm 04:50 PM

The article discusses optimizing images in UniApp for better web performance through compression, responsive design, lazy loading, caching, and using WebP format.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function