--- name: react-to-taro description: Transpile React Web applications (v18+) into Taro 4.x code optimized for WeChat Mini Program. Use this skill when converting React components, pages, or utilities to Taro-compatible code with proper JSX element mapping, event handler transformation, navigation/routing conversion, and API shim layer. license: MIT compatibility: Taro 4.x, React 18+, WeChat Mini Program, weapp-tailwindcss metadata: version: "1.0.0" target-platform: weapp source-framework: react output-framework: taro allowed-tools: Read Edit Write Glob Grep Bash --- # React to Taro WeChat Mini Program Compiler You are an advanced autonomous agent skill designed to transpile React Web applications into **Taro 4.x** code optimized for WeChat Mini Program. You possess deep knowledge of Taro 4.x architecture, performance patterns, component APIs, and weapp-tailwindcss integration. ## Scripts (辅助脚本) 此 Skill 提供三个辅助脚本用于分析和验证转换工作: ### 1. analyze.js - 代码分析器 扫描 React 源代码,生成转换报告,标记需要处理的位置。 ```bash node scripts/analyze.js # 输出: taro-migration-report.json ``` **检测内容:** - JSX 元素 (div, span, img, input 等) - 事件处理器 (onChange, onKeyDown 等) - 路由代码 (react-router-dom) - Web API (axios, localStorage, DOM) ### 2. generate-transforms.js - 转换指令生成器 读取分析报告,生成具体的转换指令供 Agent 执行。 ```bash node scripts/generate-transforms.js taro-migration-report.json # 输出: taro-transforms.json ``` ### 3. validate.js - 代码验证器 检查转换后的 Taro 代码是否符合规范。 ```bash node scripts/validate.js # 验证通过返回 0,失败返回 1 ``` **验证规则:** - 无 Web 原生元素 - 无 react-router-dom - 无 DOM API / localStorage - 无 e.target.value (应为 e.detail.value) - 无 undefined state ### 推荐工作流 ```bash # 1. 分析源代码 node scripts/analyze.js ./src # 2. 生成转换指令 node scripts/generate-transforms.js taro-migration-report.json # 3. Agent 根据指令执行转换 (手动) # 4. 验证转换结果 node scripts/validate.js ./src-taro ``` --- ## Input Context You will receive React Web source code for transformation. Identify the file type: - **component**: React functional/class component - **page**: React page with routing - **app_entry**: App entry point with routes - **utility**: Helper functions/hooks ## Operational Protocol Your output must be **production-ready code** only. Do not provide markdown explanations unless specifically asked for "analysis". --- # RULESET A: IMPORT TRANSFORMATION ## Destroy List (Remove These) ```typescript // React Router import { Link, useNavigate, useLocation, useParams, Outlet, NavLink } from 'react-router-dom' // Web Animation Libraries import { motion, AnimatePresence } from 'framer-motion' // Direct Axios import axios from 'axios' // Browser APIs import { createPortal } from 'react-dom' ``` ## Inject List (Add These) ```typescript // Core Taro (Always) import Taro, { useLoad, useDidShow, useReady } from '@tarojs/taro' // Components (As Needed) import { View, Text, Image, Button, Input, Textarea, ScrollView, Swiper, SwiperItem, RichText, CustomWrapper, Form, Navigator } from '@tarojs/components' // Types (TypeScript) import type { CommonEvent, ITouchEvent } from '@tarojs/components' ``` --- # RULESET B: JSX ELEMENT MAPPING ## Container Elements → View | React | Taro | |-------|------| | `
`, `
`, `
`, `
` | `` | | `