Overview
@morjs/plugin-compiler is the core build plugin for MorJS. It registers the compile CLI command, builds a Webpack configuration from user config, transforms source files through platform-specific parser plugins, and bundles the output for the requested target platform.
| Property | Value |
|---|---|
| Package | @morjs/plugin-compiler |
| Version | 1.0.113 |
| Command | mor compile |
Installation
Usage
Register the plugin on aTakin instance:
@morjs/cli:
MorCompilerPlugin
The default export. Implements the Takin Plugin interface.
apply is called, MorCompilerPlugin instantiates an internal MorCompile object that:
- Registers the
compileCLI command with all supported target options. - Applies parser plugins for config, script, style, template, and SJS files.
- Applies optimisation and injection plugins (alias, define, runtime inject, split chunks, etc.).
- Applies all compiler plugins returned by
getComposedCompilerPlugins(). - Hooks into the
userConfigValidatedstage to apply default config and build the Webpack configuration.
Exported utilities
applyDefaults
Applies MorJS-managed default values to a CompilerUserConfig object. Called automatically during userConfigValidated.
COMPILE_LOADERS
An object containing all webpack loader configurations used by the compiler. Exposed so that third-party plugins can reference or extend them.
getCompilerLoaders:
preprocess
A code preprocessor function that evaluates conditional compilation directives (#ifdef, #ifndef, #endif) in source files.
The source code string to preprocess.
A map of condition names to boolean values used to evaluate directives.
getAllCompilerTargets
Returns an array of all registered target platform identifiers (e.g. 'wechat', 'alipay', 'baidu', 'bytedance', 'qq', 'kuaishou').
getComposedCompilerPlugins
Returns the merged set of all registered compiler plugins, keyed by plugin name and target description.
getComposedCompilerPlugins:
CompilerUserConfig
The user-facing configuration type for the compile command. Key fields:
DSL source type of the project being compiled.
Compilation target platform. Must be one of the values returned by
getAllCompilerTargets().Source directory. Defaults to
'src'.Output directory. Defaults to
dist/<target>.Enable file-watch mode. Equivalent to
--watch on the CLI.Compilation mode:
'bundle' (default) or 'transform'.Additional Takin plugins to load for this compilation run.
Runner methods registered
| Method name | Returns | Description |
|---|---|---|
getCompilerLoaders | typeof COMPILE_LOADERS | All webpack loader configs |
getComposedCompilerPlugins | ComposedCompilerPlugins | All registered compiler plugins |