Split the PSD layer structure into multiple independent component files by first-level groups, supporting React (JSX + CSS Modules) and Vue (SFC).
Quick Start
React
py -3 .claude/skills/psd-component-splitter/scripts/split_components.py \
--json layer-tree.json \
--images sliced-images/ \
--out output/ \
--framework react
Output directory:
output/react-split/
Vue
py -3 .claude/skills/psd-component-splitter/scripts/split_components.py \
--json layer-tree.json \
--images sliced-images/ \
--out output/ \
--framework vue
Output directory:
output/vue-split/
Prerequisites
# 1. 导出图层切片
py -3 .claude/skills/psd-slicer/scripts/export_slices.py \
design.psd -o sliced-images/
# 2. 生成图层结构 JSON
py -3 .claude/skills/psd-layer-reader/scripts/psd_layers.py \
design.psd -o layer-tree.json
Parameter Description
| Parameter | Required | Description |
|---|---|---|
--json |
✅ | JSON layer tree file path |
--images |
✅ | Slice image directory path |
--out |
✅ | Output directory path |
--framework |
✅ | react or vue |
--component-name |
❌ | Main component name (default:PsdApp) |
Output Structure
The script automatically creates the corresponding subdirectory under the output directory based on the framework type:
- React:
<out>/react-split/ - Vue:
<out>/vue-split/
React
output/react-split/
├── App.jsx # 主入口组件
├── App.module.css # 全局样式
├── components/ # 组件目录
│ ├── group-header/
│ │ ├── index.jsx
│ │ └── index.module.css
│ └── ...
└── images/ # 图片资源
└── ...
Vue
output/vue-split/
├── App.vue # 主入口组件
├── components/ # 组件目录
│ ├── group-header/
│ │ └── index.vue
│ └── ...
└── images/ # 图片资源
└── ...
How It Works
- Parse JSON: Read the layer tree structure
- Identify groups: Traverse first-level layers, identify
kind: "group"nodes - Generate components: Convert group names to PascalCase (e.g.
user-card→UserCard) - Create entry: Generate App.jsx/App.vue integrating all subcomponents
- Copy assets: Copy images to the
images/directory
Component Features
React
- CSS Modules style isolation
- Support
className、style、onClickprops - BEM class naming convention
Vue
- Single-File Components (SFC)
- Scoped CSS
- Support props passing
Usage Recommendations
✅ Applicable Scenarios
- PSD first-level groups represent different functional modules
- Componentized development is needed, with each module maintained independently
- Team collaborative development
❌ Inapplicable Scenarios
- PSD has no clear group structure
- Pixel-perfect single-page preview is needed (use psd-json-preview)
- Responsive flexbox layout is needed (use psd-semantic-layout)
Troubleshooting
No valid first-level groups found
Cause: There is no first-level node with kind: "group" in the PSD structure
Solution:
- Check the JSON structure to confirm group layers exist
- Create groups in the PSD and re-export
Component generation failed
Cause: Generator module not found or script path is incorrect
Solution:
- Confirm the script directory structure is complete
- Check whether
react_generator.pyorvue_generator.pyexists
Images not copied
Cause: Image names do not match layer names
Solution:
- Use the
--mapping-jsonparameter when slicing - Check whether the
namefield in the JSON matches the image file names
Related Skills
- psd-layer-reader - Read PSD layer structure as JSON
- psd-slicer - Export PSD layers as PNG images
- psd-json-preview - Generate HTML preview
- psd-semantic-layout - Generate semantic flexbox layout
Detailed Documentation
For the complete workflow, practical examples, and common questions, see references/WORKFLOW.md。