Awesome-omni-skill react-to-wx-miniprogram-migrator
Migrates a React + TailwindCSS H5 web application to a native WeChat Mini Program. Use when the user wants to convert their existing web project into a mini program, preserving structure, styling, and functionality.
git clone https://github.com/diegosouzapw/awesome-omni-skill
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/development/react-to-wx-miniprogram-migrator" ~/.claude/skills/diegosouzapw-awesome-omni-skill-react-to-wx-miniprogram-migrator && rm -rf "$T"
skills/development/react-to-wx-miniprogram-migrator/SKILL.mdReact + TailwindCSS to WeChat Mini Program Migration Skill
This skill provides a systematic process for an AI agent to migrate a web application built with React and TailwindCSS into a native WeChat Mini Program. The goal is to achieve a functional and stylistically faithful conversion by mapping modern web development patterns to the specific architecture of WeChat Mini Programs.
When to Use This Skill
Use this skill when the user explicitly requests to convert a React-based H5 website, especially one using TailwindCSS for styling, into a native WeChat Mini Program. The source code of the React project should be available for analysis.
Migration Process Overview
The migration is a multi-step process that involves code transformation, style conversion, and API replacement. Follow these steps sequentially for a successful migration.
- Analyze Source & Setup Project: Analyze the React project structure and set up a corresponding WeChat Mini Program project.
- Component & JSX to WXML Conversion: Convert React components and JSX syntax into Mini Program components and WXML structure.
- TailwindCSS to WXSS Conversion: Transform TailwindCSS utility classes into equivalent WXSS styles.
- Logic & State Management Migration: Adapt React's state management (Hooks, Redux) and lifecycle to the Mini Program's
anddata
system.setData - Routing & Navigation Replacement: Replace web-based routing (e.g., React Router) with the Mini Program's page navigation API.
- API & SDK Replacement: Substitute browser/web APIs (e.g.,
,fetch
) with their WeChat Mini Program counterparts (localStorage
,wx.request
).wx.setStorageSync - Asset & Resource Handling: Migrate and correctly reference static assets like images and fonts.
- Final Review & Debugging: Thoroughly test the migrated application in the WeChat DevTools and on a physical device.
Step-by-Step Migration Instructions
Step 1: Analyze Source & Setup Project
- Analyze React Project: Use the
orls -R
command to inspect the source React project's directory structure. Identify the main components, pages, utility functions, and static assets.tree - Create Mini Program Structure: Based on the analysis, create a standard WeChat Mini Program directory structure. Refer to
for the standard structure.references/MIGRATION_MAP.md- Create the
,app.js
, andapp.json
root files.app.wxss - Create a
directory and subdirectories for each page identified in the React app.pages - Create a
directory for reusable components.components - Create a
directory for helper functions.utils
- Create the
- Configure
: Populate theapp.json
file. List all the pages in theapp.json
field. If the H5 app has a tab bar, configure thepages
field accordingly.tabBar
Step 2: Component & JSX to WXML Conversion
This is the core of the UI migration. Convert each React component into a Mini Program component folder containing
.js, .wxml, .wxss, and .json files.
- Map HTML Tags to WXML Components: For each JSX file, systematically replace HTML tags with their corresponding WXML component equivalents. A detailed mapping can be found in
.references/MIGRATION_MAP.md
->divview
,span
,p
-h1
->h6text
->imgimage
->anavigator
->buttonbutton
- Convert JSX Syntax: Transform JSX control flow and expressions into WXML directives.
- List Rendering: Convert
calls to.map()
loops.wx:for - Conditional Rendering: Convert
,&&
operators to? :
,wx:if
,wx:elif
directives.wx:else - Data Binding: Convert
to{variable}
.{{variable}} - Event Handling: Convert
toonClick={handler}
.bindtap="handler"
- List Rendering: Convert
Step 3: TailwindCSS to WXSS Conversion
This is a critical and potentially complex step. The primary challenge is converting utility-first CSS into static WXSS stylesheets, as Mini Programs do not have a JIT compiler for styles.
- Identify All Tailwind Classes: Scan all JSX files and extract every TailwindCSS class name used.
- Convert Classes to CSS: Use an online tool or a script to convert the list of Tailwind classes into standard CSS. You can use this Tailwind to CSS Converter for this purpose.
- Adapt CSS for WXSS: Manually adjust the generated CSS to be compatible with WXSS.
- Convert Units: Change
orpx
units torem
. A common baseline isrpx
(16px) =1rem
. Use this as a general rule but adjust for precision.32rpx - Handle Unsupported Selectors: Replace unsupported selectors like the universal selector (
) or complex descendant selectors.* - Address
Property: Sincegap
is not supported, implement spacing between flex/grid items usinggap
on the child elements.margin
- Convert Units: Change
- Organize Styles: Paste the converted styles into the appropriate
files. Global styles (from.wxss
orindex.css
) go intoApp.css
, and component-specific styles go into the component'sapp.wxss
file..wxss
Step 4: Logic & State Management Migration
- Component Logic: Move the logic from the React component function body into the
orPage({...})
object in theComponent({...})
file..js - State Management: Refactor React state to the Mini Program's
object.data- Convert
declarations to initial values in theuseState
object.data - Replace state update calls (e.g.,
) withsetCount(1)
.this.setData({ count: 1 })
- Convert
- Lifecycle Methods: Map React's lifecycle hooks to Mini Program lifecycle methods. See
for a detailed mapping.references/MIGRATION_MAP.md
with an empty dependency arrayuseEffect
maps to[]
.onLoad
with no dependency array maps roughly touseEffect
.onShow- The return function from
maps touseEffect
.onUnload
Step 5: Routing & Navigation Replacement
Replace all instances of React Router or other routing libraries with the Mini Program's built-in navigation API.
or<Link to="/path">
becomesnavigate('/path')
.wx.navigateTo({ url: '/pages/path/index' })- Use
for navigating to tab bar pages.wx.switchTab - Use
for redirects.wx.redirectTo - Use
for going back.wx.navigateBack
Step 6: API & SDK Replacement
Replace all browser-specific APIs with their
wx. counterparts.
- Network Requests: Replace
orfetch
withaxios
.wx.request - Local Storage: Replace
withlocalStorage
andwx.setStorageSync
.wx.getStorageSync - DOM Manipulation: Remove all direct DOM manipulation code (e.g.,
). Instead, use data binding to control the view.document.getElementById
Step 7: Asset & Resource Handling
- Images: Move all image assets into a dedicated directory (e.g.,
). Update all/images<image>
paths to be absolute paths from the project root (e.g.,src
)./images/logo.png - Fonts: If custom fonts are used, they need to be loaded using
inwx.loadFontFace
.app.js
Step 8: Final Review & Debugging
- Use WeChat DevTools: This is your primary environment for testing and debugging. Check the console for errors and use the WXML panel to inspect the UI structure.
- Test on Device: Preview the Mini Program on a physical device to check for performance issues and styling inconsistencies that may not appear in the simulator.
- Iterate and Refine: The migration process is iterative. Expect to go back and forth between steps to fix bugs and refine the user experience.
Bundled Resources
: Contains detailed mapping tables for components, events, lifecycles, and APIs to assist in the conversion process.references/MIGRATION_MAP.md