search
HomeWeb Front-enduni-appLearn more about subcontracting steps in uniapp and mini programs

How to subcontract uniapp and mini program? The following article will give you a detailed understanding of the subcontracting steps of uniapp and mini programs. I hope it will be helpful to you!

Learn more about subcontracting steps in uniapp and mini programs

1. Mini program sub-packaging

Each mini program that uses sub-packaging 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.

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 exceed 2M Subcontracting mini programs can optimize the download time for the first launch of the mini program, and enable better decoupling and collaboration when multiple teams develop together.

Click here directly to see the official subpackaging tutorial which is easy to understand:

https://developers.weixin.qq.com/miniprogram/dev/framework/subpackages/basic. html

2. uniapp subcontracting applet

App defaults to the whole 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. [Related recommendations: "uniapp tutorial"]

  • components: Public components (for reference by the main package)
  • page_followed by pinyin are all sub-packages
  • The components in a subpackage are the component directories of a single subpackage. The reference to the subcontracted vue page can only be referenced in its own page_xxxx subcontracting directory.
  • pages is the main package, which They are all startup pages/TabBar pages.
  • static places public static resources, and image classes

Subcontracting steps:

1. Configure manifest.json

"mp-weixin": {
"optimization":{"subPackages":true}
}

Learn more about subcontracting steps in uniapp and mini programs

Optimize subcontracting:

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

Currently only supports subpackage optimization for mp-weixin, mp-qq, and mp-baidu

  • Static files: Sub-packaging supports copying of static resources such as static, that is, static resources placed in the sub-packaging directory will not be packaged into the main package, and
  • js files cannot be used in the main package: When a certain js is only referenced by one sub-package, the js will be packaged into the sub-package, otherwise it will still be packaged in the main package (that is, 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 during compilation

2. Configuration pages .json

Create a new array "subPackages" in pages.json. The array contains two parameters: 1.root: the root directory of the subpackage, 2.pages: which pages the subpackage 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 sub-contracting;

Learn more about subcontracting steps in uniapp and mini programs

3. Subcontracting preload configuration (preloadRule)

This step is mainly done to optimize the speed. If you don’t want to optimize the 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 subpackages that may be needed to improve the startup speed when entering subsequent subpackage pages.

In preloadRule, the key is the page path , value is the pre-downloaded configuration entering this page. Each configuration has the following items:

Field Type Required Default value Description
packages StringArray is None After entering the page, pre-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-download under wifi)

app subpackage, preloadRule is also supported, but the network rules are invalid.

You can view the official configuration items:

https://uniapp.dcloud.io/collocation/pages?id=subpackages

This article is reproduced from: https://juejin.cn/post/7003138257798037512

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of Learn more about subcontracting steps in uniapp and mini programs. 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

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools