Adding plugins to your config
Plugins are passed in theplugins array of a config entry. Each plugin is an instance of a class that implements the Plugin interface.
mor.config.ts
Official plugins
All official plugins are bundled inside@morjs/cli and do not need to be installed separately. They register their own CLI commands and configuration schemas automatically.
@morjs/plugin-analyzer
Bundle size analysis via
webpack-bundle-analyzer.@morjs/plugin-mocker
API mock layer injected at compile time for development.
@morjs/plugin-composer
Assembles multiple independently compiled subpackages into a host app.
@morjs/plugin-generator
Scaffolding generator used by
mor create.@morjs/plugin-analyzer
Adds a standalone mor analyze command that runs a bundle analysis on your project. It internally triggers mor compile in bundle mode with webpack-bundle-analyzer enabled, writing output to dist/analyzer.
CLI usage
Config usage
The analyzer can also be triggered inline via theanalyzer field in mor.config.ts:
true to use defaults:
@morjs/plugin-mocker
Injects a mock runtime into the compiled output during development. Mock files are loaded from a configurable directory using require.context.
Enabling mocks
Pass--mock on the CLI (only active in non-production mode):
Configuration
mor.config.ts
Mock file format
Place mock files in yourmock/ directory. Each file exports mock responses keyed by API name:
mock/request.js
@morjs/plugin-composer
Orchestrates multi-repo mini-program projects by downloading, compiling (or copying), and assembling subpackages into a host application.
mor compose command
Configuration
Add ahost and modules array to your config:
mor.config.ts
Module types
| Type | Description |
|---|---|
subpackage | Pages are inserted into app.json subPackages. |
main | Pages are inserted into app.json pages. |
plugin | Plugin config is fetched and route support is written. |
Integration modes
| Mode | Description |
|---|---|
compose | Copy pre-built artefacts directly to the output directory. |
compile | Run the full mor compile pipeline on the module source. |
@morjs/plugin-generator
Provides project scaffolding and code generation. It exposes two commands: mor init / mor create for creating new projects, and mor generate / mor g for scaffolding pages and components within an existing project.
Create a new project
Generate pages or components
--src-path, --source-type, --typescript, --less, or --scss flags to control the generated output:
Writing a custom plugin
A MorJS plugin is a class with aname property and an apply(runner) method. Use runner hooks to intercept and modify the compilation pipeline.
mor.config.ts