# Use of sub-packageing

# Configuration method

Suppose the Weixin Mini Program directory supporting sub-packageing is structured as follows:

├── app.js
├── app.json
├── app.wxss
├── packageA
│   └── pages
│       ├── cat
│       └── dog
├── packageB
│   └── pages
│       ├── apple
│       └── banana
├── pages
│   ├── index
│   └── logs
└── utils

The developer declares the project subcontract structure in the apagejsonsubPackagesfield:

Written assubpackagesare also supported.

{
  "pages":[
    "pages/index",
    "pages/logs"
  ],
  "subPackages": [
    {
      "root": "packageA",
      "pages": [
        "pages/cat",
        "pages/dog"
      ],
      "entry": "index.js"
    }, {
      "root": "packageB",
      "name": "pack2",
      "pages": [
        "pages/apple",
        "pages/banana"
      ]
    }
  ]
}

In subPackages, each subpackage is configured with the following:

field type Introductions
root String Subpackage root directory
name String Subcontract aliases, Subcontract predownloads
pages StringArray Sublot page path, as opposed to sublot root directory
independent Boolean Whether the subcontract is independent subcontract
entry String Subcontract entry documents

# Packing Principles

  • When you declaresubPackages, you will be packaged by thesubpackagesconfiguration path, and thesubpackagesdirectories outside the configuration path will be packagened into the main package
  • The main package can also have its own pages, the outermost pages field.
  • The root directory of subPackagescannot be a subdirectory within anothersubPackages
  • TabbarThe page must be within the main package

# Principles of Reference

  • Packageacannot requirepackageBJSFiles, but may require JS files within the main package,packageA;Use of subcontract asynchronization is not restricted by this
  • PackageaUnable to importpackageB`` packageA
  • PackageAcannot use the resources ofpackageB, but you can use the resources within the main package,packageA

# Subcontract entry documents

In the configuration of each subpackage, theentryfield can specify any JavaScript file in the subpackage as the entry file that is executed first when the subpackage is injected.

The specified JS file should fill in the path relative to the packet root directory, for example by specifying/path/to/subPackage/src/index.js``/ path / to / subPackage`` src/index.js

The WeChat developer tool version 1.06.2406242 or above is required to debug this feature. No version is required for the formal environment.

Preview with Developer Tool

# Example projects

Download Weixin Mini Program sample (subcontract loaded version) source code