Runtime packages
@morjs/runtime-mini
Platform adapters for each supported mini-program target. Contains API transform configs and component/page adapters for every source-to-target combination.
@morjs/runtime-base
Shared utilities used by all runtimes: environment detection, event system, hooks, logger, base64, and API transform infrastructure.
@morjs/runtime-web
Web-specific runtime that maps mini-program APIs and components to browser equivalents when targeting the
web platform.What the runtime provides
At a high level,@morjs/runtime-mini normalizes four categories of cross-platform difference:
- API normalization — rewrites method names, parameter keys, and response shapes so Alipay APIs work on WeChat and vice versa.
- Page adapters — adapts page lifecycle methods and data between source and target.
- Component adapters — adapts component lifecycle, properties, and events.
- Behavior/Mixin adapters — bridges WeChat
Behaviorand AlipayMixinidioms.
sourceType and target values used at compile time. The runtime skips all transformation when source and target are the same platform.
Auto runtime injection
MorJS automatically injects runtime wrappers at compile time. TheautoInjectRuntime configuration controls which constructors are wrapped:
autoInjectRuntime is true (the default for cross-platform compilation), MorJS replaces each constructor call with its MorJS-wrapped equivalent:
| Original call | Injected wrapper | Default when cross-compiling |
|---|---|---|
App({}) | MorJS app runtime | true |
Page({}) | MorJS page runtime | true |
Component({}) | MorJS component runtime | true |
Behavior({}) | MorJS behavior runtime | true (non-Alipay source) |
Mixin({}) | MorJS mixin runtime | true (Alipay source only) |
false to autoInjectRuntime to disable all injection entirely.
GlobalObjectTransformTypes
Theapi key within autoInjectRuntime controls how the global object (wx, my, etc.) is transformed. Three modes are available:
enhanced — full API normalization
enhanced — full API normalization
wx is replaced with mor, and the MorJS API shim is imported. The shim contains the full API transform config, normalizing method names, parameter keys, and response shapes.enhanced when you need full API compatibility across platforms.lite — direct global replacement
lite — direct global replacement
Every occurrence of the source global object is replaced with the target global object. No import is added; the raw target API is called directly.Use
lite when the APIs you call have identical signatures on source and target, and you do not need normalization overhead.minimal — function call replacement only
minimal — function call replacement only
Only function call expressions on the global object are rewritten. Property accesses that are not function calls are left as-is.
createApp / createPage / createComponent
The@morjs/core package exports platform-agnostic constructors that wrap the native mini-program constructors with cross-platform adapter chains:
| Export | Description |
|---|---|
createApp | Cross-platform App() wrapper |
aApp | Alipay-flavored App() wrapper |
wApp | WeChat-flavored App() wrapper |
createPage | Cross-platform Page() wrapper |
aPage | Alipay-flavored Page() wrapper |
wPage | WeChat-flavored Page() wrapper |
createComponent | Cross-platform Component() wrapper |
aComponent | Alipay-flavored Component() wrapper |
wComponent | WeChat-flavored Component() wrapper |
autoInjectRuntime is enabled, MorJS replaces your native App({}), Page({}), and Component({}) calls with these wrappers automatically at compile time. You only need to call them explicitly if you opt out of auto-injection.
Runtime source type markers
At compile time, MorJS embeds source type markers to let the runtime know which adapter set to use:@morjs/runtime-mini’s initAdapters function, which registers the appropriate page adapters, component adapters, and API transform configs for the source-to-target combination.
The runtime skips all adapter registration when
sourceType === target. No overhead is added in same-platform builds.