- Code-level — remove or keep blocks of code based on variables in
conditionalCompile.context. - File-level — resolve platform-specific file variants based on
conditionalCompile.fileExt.
Configuration
Both options live underconditionalCompile in mor.config.ts:
Code-level conditional compilation
conditionalCompile.context defines the variable set evaluated when the compiler encounters conditional compile directives in your source files.
Directives
Directives are written as comments. The compiler strips the surrounding comment markers and evaluates the expression against the context:Using built-in target context
The compiler automatically injects the currenttarget value as TARGET into the context. You can use it without any extra config:
Adding custom context variables
File-level conditional compilation
conditionalCompile.fileExt controls file-extension-based resolution. When this option is set to 'alipay', MorJS resolves button.alipay.ts in preference to button.ts when compiling for Alipay.
Default fileExt values by target
Each compiler target plugin declares adefaultConditionalFileExt property. You do not need to set fileExt unless you want to override the default:
| Target | Default fileExt |
|---|---|
alipay | alipay |
wechat | wechat |
baidu | baidu |
bytedance | bytedance |
qq | qq |
taobao | taobao |
dingding | dingding |
web | web |
Providing platform-specific file variants
Create sibling files with the target extension as an additional suffix:Multiple fileExt values
Pass an array to check multiple extensions in priority order:platform.alipay.ts first, then platform.mini.ts, and falls back to platform.ts.