What are subpackages?
Mini-programs support splitting the application into a main package and one or more subpackages. Subpackages are downloaded on demand, keeping the initial load size small. Each subpackage is defined inapp.json under subPackages.
MorJS supports compiling subpackages independently via compileType: 'subpackage', with a dedicated subpackage.json entry file.
Subpackage entry file
WhencompileType is subpackage, MorJS looks for subpackage.json as the entry (instead of app.json). This file declares the pages belonging to the subpackage:
src/subpackage.json
Compiling a subpackage
SetcompileType: 'subpackage' in mor.config.ts:
mor.config.ts
Independent subpackages
An independent subpackage can run without the main package being downloaded first. MorJS compiles it with its own app init file.src/subpackage.json
independent flag and creates an isolated compilation context for the subpackage so its runtime does not depend on the main package.
Custom entry files
UsecustomEntries to point to a non-standard location for any of the entry config files:
Module sharing between main and subpackages
When the main package and subpackages are developed in separate repositories and assembled at integration time, you can avoid duplicating shared npm modules usingshared and consumes.
shared — main package exposes modules
The main package declares which npm modules it will share at runtime:
mor.config.ts (main package)
shared are included in the main package bundle and exposed under a predictable global name so subpackages can reference them without rebundling.
consumes — subpackage uses shared modules
The subpackage declares which modules to consume from the main package instead of bundling them locally:
mor.config.ts (subpackage)
Named module mapping
You can alias a module when sharing or consuming it:Integration with plugin-composer
For larger multi-team projects,@morjs/plugin-composer automates the assembly of main and subpackage outputs into a single deliverable. It works in conjunction with compileType: 'subpackage' compilation. See the Plugins guide for setup details.