Using Subpackages
Configuration Method
Assuming the directory structure of a miniApp that supports subpackages is as follows:
├── app.js
├── app.json
├── app.css
├── packageA
│ └── pages
│ ├── cat
│ └── dog
├── packageB
│ └── pages
│ ├── apple
│ └── banana
├── pages
│ ├── index
│ └── logs
└── utils
Developers can declare the subpackage structure of the project in the subPackages
field of app.json
:
{
"pages": ["pages/index/index", "pages/logs/index"],
"subPackages": [
{
"root": "packageA",
"pages": ["pages/cat/index", "pages/dog/index"]
},
{
"root": "packageB",
"name": "pack2",
"pages": ["pages/apple/index", "pages/banana/index"]
}
]
}
Within subPackages
, each subpackage has the following configuration items:
Field | Type | Description |
---|---|---|
root | String | Root directory of the subpackage |
name | String | Alias of the subpackage, which can be used in subpackage preloading |
pages | String[] | Paths to the pages of the subpackage, relative to the root directory |
Packaging Principles
- After declaring
subPackages
, the paths configured insubPackages
will be packaged, and directories outside thesubPackages
configuration paths will be packaged into the main package; - The main package can also have its own pages (i.e., the outermost
pages
field). - The root directory of a
subPackages
cannot be a subdirectory within anothersubPackages
. - The tabBar pages of the homepage must be within the main package.
Referencing Principles
- Two subpackages cannot reference each other's JS files, but subpackages can reference JS files from the main package or within their own subpackage.
- The main package cannot reference JS files from subpackages.
Compatibility with Older Versions
The IDE handles compatibility with older versions of the client. The IDE will compile two sets of code packages: one for the subpackaged code and another for the whole package compatibility code. When uploading a version, the code packages are submitted to the backend. The new client uses subpackages, while the old client still uses the whole package. The whole package will include paths from each subPackages
in the pages
field.