Configuration
SetsourceType to wechat and target to alipay in your mor.config.ts:
sourceType defaults to wechat. If your project only has .wxml files and
no .axml files, MorJS will auto-detect the DSL without an explicit setting.File Extension Mapping
The compiler rewrites every source file extension to the Alipay equivalent:| Alipay | Purpose | |
|---|---|---|
.wxml | .axml | Template |
.wxss | .acss | Styles |
.wxs | .sjs | Script modules |
.js | .js | Page / component logic |
.json | .json | Configuration |
dist/alipay.
Global Object: wx → my
Alipay exposes its API through my; WeChat uses wx. MorJS handles this
transformation at compile time through the autoInjectRuntime.api setting,
which accepts one of three modes defined in GlobalObjectTransformTypes:
enhanced (default for cross-platform builds)
enhanced (default for cross-platform builds)
Replaces This is the recommended mode. It enables the runtime API transform table
described in the API Differences section below.
wx with a MorJS proxy object (mor) and inserts a
import-style injection at the top of each script file. The proxy holds a
fully normalised API surface that maps WeChat calls to Alipay equivalents,
including argument renaming, promise wrapping, and return-value mapping.lite
lite
A lightweight textual replacement: every occurrence of the identifier
wx
is replaced with my. No additional import is injected. Use this when your
code calls only APIs that have identical signatures on both platforms.minimal
minimal
Only replaces
wx.<method>() call expressions — bare references like
const g = wx are left untouched.Template Directive Mapping
WeChat template directives (wx:) are rewritten to Alipay directives (a:) at
compile time:
| WeChat directive | Alipay directive |
|---|---|
wx:if | a:if |
wx:elif | a:elif |
wx:else | a:else |
wx:for | a:for |
wx:for-item | a:for-item |
wx:for-index | a:for-index |
wx:key | a:key |
| Alipay | |
|---|---|
<wxs src="..." module="m"> | <import-sjs from="..." name="m" /> |
Alipay’s
<import-sjs> tag does not support inline script content
(isSupportSjsContent: false). Split any inline <wxs> blocks into
separate .sjs files before migrating.Runtime Injection: autoInjectRuntime
In enhanced mode, MorJS replaces the WeChat constructor calls with its own
runtime wrappers so that Alipay-specific lifecycle conventions are satisfied
automatically:
| WeChat call | Injected MorJS runtime |
|---|---|
App({}) | aApp({}) from @morjs/runtime-mini |
Page({}) | aPage({}) |
Component({}) | aComponent({}) |
Behavior({}) | mapped to Alipay Mixin({}) via behaviorOrMixin |
API Differences
Theenhanced runtime (apisToAlipay.ts) translates the following WeChat APIs
to their Alipay equivalents automatically. No code changes are required in your
source.
- UI
- Storage
- Network
- Auth / User
- Device
- BLE
| WeChat API | Alipay API | Notes |
|---|---|---|
wx.showActionSheet({ itemList }) | my.showActionSheet({ items }) | Parameter renamed |
wx.showToast({ title, icon }) | my.showToast({ content, type }) | icon: 'loading' delegates to my.showLoading |
wx.showLoading({ title }) | my.showLoading({ content }) | Parameter renamed |
wx.showModal() | my.confirm() / my.alert() | showCancel: false uses alert |
wx.setNavigationBarTitle | my.setNavigationBar | Mapped |
wx.setNavigationBarColor | my.setNavigationBar | Mapped; front color auto-derived from background |
wx.previewImage({ current, urls }) | my.previewImage({ current (index), urls }) | current converted from URL to numeric index |
Component Lifecycle Mapping
WeChat and Alipay components have different lifecycle names. TheaComponent
runtime maps them:
| Alipay | |
|---|---|
created | onInit |
attached | didMount (via composed lifecycle) |
ready | didMount |
detached | didUnmount |
error | onError |
Behavior({}) constructor is mapped to Alipay’s Mixin({}) via the
behaviorOrMixin runtime module.
Common Gotchas
Inline wxs content is not supported
Inline wxs content is not supported
Alipay’s
<import-sjs> tag cannot contain inline script. Any WeChat page
that embeds JS inside a <wxs> tag must have that code extracted into a
separate .sjs file and referenced with from=.style prop on custom components
style prop on custom components
Alipay does not support a raw
style prop on custom components.
MorJS automatically renames style → morStyle on component nodes and
adds a corresponding observer that copies the value back. Avoid passing
computed style strings directly as style to custom components — use a
wrapper view instead.Module resolution order
Module resolution order
The Alipay compiler resolves npm package
main fields in the order:
alipay → module → main. Ensure any cross-platform component library
you depend on exports an alipay field in its package.json or the
correct file will be missing.Script target and module format
Script target and module format
Alipay compiles scripts to ES2015 with ESNext module syntax by
default, whereas WeChat uses ES5 + CommonJS. Libraries that ship
only CommonJS bundles may need to be processed via
processNodeModules.Component styleIsolation
Component styleIsolation
Alipay does not support setting
styleIsolation through the Component
constructor options. Set it in the component’s .json file instead:createSelectorQuery().in() is a no-op
createSelectorQuery().in() is a no-op
wx.createSelectorQuery().in(component) scopes query results to a
component. Alipay’s equivalent does not take a component argument;
the runtime shim keeps the .in() method but it has no effect.
Queries will search the full page tree.Conditional Compilation
Use MorJS conditional compilation to ship platform-specific code in the same source file:.wx.js /
.my.js suffix convention configured in conditionalCompile.fileExt.