uniapp subPackages sub-package loading configuration

1. Subcontract loading configuration

Subpackage loading configuration, this configuration is a subpackage loading mechanism for applets.
The subPackages node receives an array. Each item in the array is an applied subpackage, and its property values ​​are as follows:
Insert picture description here
Note:

The paths of pages in subPackages are relative paths under root, not full paths.
The size of each sub-package of WeChat and Baidu applets is 2M, and the total volume cannot exceed 8M.
The size of each sub-package of Alipay applet is 2M, and the total volume cannot exceed 4M.
Support independent static directory under subcontracting to subcontract static resources.
The uni-app supports optimization of WeChat applets, QQ applets, and Baidu applets. Putting static resources or js files into subpackages does not occupy the size of the main package. For details, please refer to: Notes on subcontracting optimization.
If the vendor.js is too large, you can use the runtime compression code to
create the project created by HBuilderX. Check Run-> Run to Mini Program Emulator-> Whether
the project created by the code cli is compressed at runtime. can add parameters -minimize, in the example in pacakge.json: "dev: mp-weixin" : "cross-env NODE_ENV = development UNI_PLATFORM = mp-weixin vue-cli-service uni-build --watch --minimize"
use :

Assuming that the sub-package uni-app directory structure is as follows:
Insert picture description here
you need to fill in pages.json

{
    "pages": [{
        "path": "pages/index/index",
        "style": { ...}
    }, {
        "path": "pages/login/login",
        "style": { ...}
    }],
    "subPackages": [{
        "root": "pagesA",
        "pages": [{
            "path": "list/list",
            "style": { ...}
        }]
    }, {
        "root": "pagesB",
        "pages": [{
            "path": "detail/detail",
            "style": { ...}
        }]
    }],
    "preloadRule": {
        "pagesA/list/list": {
            "network": "all",
            "packages": ["__APP__"]
        },
        "pagesB/detail/detail": {
            "network": "all",
            "packages": ["pagesA"]
        }
    }
}

2. preloadRule is the sub-package preload configuration

Sub-package preload configuration. In preloadRule, key is the page path and value is the pre-download configuration to enter this page. Each configuration has the following items:

Insert picture description here

29 original articles published · Liked 40 · Visits 30,000+

Guess you like

Origin blog.csdn.net/xiyunmengyuan/article/details/105409779