mpx2rn

Adapt Mpx single-file components for cross-platform React Native output.

3.9k|388|Updated Dec 6, 2018
One-click install
npx skills add https://github.com/didi/mpx --skill mpx2rn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mpx2rn
Source: https://github.com/didi/mpx/tree/main/.agents/skills/mpx2rn
Command: npx skills add https://github.com/didi/mpx --skill mpx2rn

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @mpxjs/mpx-cli-service, @mpxjs/webpack-plugin, @mpxjs/cli-shared-utils, @mpxjs/vue-cli-plugin-mpx, webpack, and includes scripts (resource) and references (resource) components.

What problem does it solve?

Mpx code written for mini-programs often breaks or behaves differently when compiled to React Native (iOS, Android, Harmony). This Skill provides the constraints, capability references, and compile validation needed to develop, migrate, and review Mpx components that run correctly on both original platforms and RN.

Core Features & Use Cases

  • Cross-platform development constraints: Enforces template, script, style, JSON config, and conditional-compilation rules so .mpx components work on mini-programs, Web, and RN simultaneously.
  • Capability references: On-demand reference docs covering RN support for template components, lifecycle/APIs, style properties, atomic CSS (UnoCSS), environment APIs, JSON config, and RN hybrid development.
  • Compile validation script: Runs real compilation of .mpx files via @mpxjs/mpx-cli-service across targets (wx, ios, web, etc.) and categorizes errors by style/template/script/json/dependency.
  • Use Case: When adapting an existing WeChat mini-program component to also ship on iOS/Android, follow the guided workflow to fix selectors, replace wx.xxx calls with mpx.xxx, isolate incompatible code with conditional compilation, then verify with the compile-validate script.

Quick Start

Ask the AI to adapt a specific .mpx component for React Native output and validate it with the compile-validate script targeting ios.

Frequently Asked Questions about mpx2rn

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I adapt an Mpx mini-program component for React Native?

Audit the component across four dimensions: check template components and events against the RN template reference, replace wx.xxx calls with mpx.xxx via @mpxjs/api-proxy, convert nested selectors to single classes, and verify JSON config fields. Isolate incompatible parts with conditional compilation, then run the compile-validate script.

How to validate Mpx component compilation for iOS and Android?

Run node scripts/compile-validate.js with the target .mpx file and --target=ios,android or other modes. The script uses the host project's @mpxjs/mpx-cli-service for real compilation and reports errors categorized by style, template, script, json, and dependency.

Does Mpx2RN support UnoCSS atomic CSS classes?

Yes, via @mpxjs/unocss-plugin and @mpxjs/unocss-base with presetMpx(). Only RN-supported utilities and variants work; hover/active pseudo variants are unsupported, and color opacity must use slash alpha syntax like bg-red-500/50 instead of separate opacity classes.

Why does my Mpx style fail to compile for React Native?

Common causes include nested or compound selectors, pseudo-classes, empty selectors left by conditional compilation, and unsupported CSS properties. RN only supports single-class selectors, so expand preprocessor nesting and wrap entire rules in conditional compilation when a platform branch would be empty.

Can I use React Native components and Hooks inside Mpx files?

Yes, register RN components in the components option and use REACTHOOKSEXEC or onReactHooksExec for Hooks. Isolate RN-specific code with file-level conditional compilation (e.g., component.ios.mpx) so mini-program and Web builds never parse react-native imports.

When should I not use this Mpx2RN skill?

Do not use it for pure mini-program development, pure React Native projects without Mpx compilation, or Mpx-to-Web output questions. It only covers the Mpx-to-React-Native compilation path for iOS, Android, and Harmony targets.