Quick Start
# 1. 分析组件(建议模式 - 只生成报告)
py -3 .claude/skills/code-splitter/scripts/split_component.py \
--input ./my-component/ \
--dry-run
# 2. 查看报告后,生成实际组件
py -3 .claude/skills/code-splitter/scripts/component_generator.py \
--input ./my-component/ \
--output ./split/
System Requirements
- Python 3.6+
- The component directory contains
index.jsxandindex.module.css
two working modes
Mode 1: Suggestion Mode
Use split_component.py to analyze and generate a report without creating files:
py -3 scripts/split_component.py --input ./my-component/ --dry-run
py -3 scripts/split_component.py --input ./my-component/ --dry-run --output report.md
py -3 scripts/split_component.py --input ./my-component/ --dry-run --min-score 0.5
Mode 2: Generate Mode
Use component_generator.py to generate actual components:
py -3 scripts/component_generator.py --input ./my-component/ --output ./split/
py -3 scripts/component_generator.py --input ./my-component/ --output ./split/ --min-score 0.5
py -3 scripts/component_generator.py --input ./my-component/ --output ./split/ --dry-run
Analysis Dimensions
Identify splittable components based on four dimensions:
- Semantic class names: identify
btn-*、card-*、header-*and other patterns - DOM structure: detect containers wrapping multiple child elements
- Repetition patterns: find similar structures (such as multiple buttons)
- Position analysis: infer Header/Footer regions from CSS
Confidence interpretation
- HIGH (≥0.8): strong recommendation to split, low risk
- MEDIUM (0.5-0.8): can be split, may need minor adjustments
- LOW (<0.5): consider carefully, it may be better to keep the current state
Output Structure
split-output/
├── app/
│ ├── index.jsx # 主入口组件
│ └── index.module.css # 主样式
├── card/ # 拆分出的子组件
│ ├── index.jsx
│ └── index.module.css
└── generation-report.json # 生成报告
Working with Other Skills
- psd-json-preview: handle generated large components
- psd-component-splitter: further optimize the split results
- frontend-code-review: review the generated component code
Reference Documentation
- Detailed Usage Guide:references/USER_GUIDE.md
- Technical Implementation Details:references/IMPLEMENTATION.md
- Troubleshooting:references/TROUBLESHOOTING.md
Known Limitations
- Only supports React function components (v2 supports Vue)
- Uses regex to parse JSX (covers 80% of common scenarios)
- Does not handle CSS-in-JS (only supports CSS Modules)
- v1 does not perform CSS coordinate conversion (copies style values as-is)
- Does not handle hooks dependencies (state remains in the original component)