---
name: vue-component-refactoring-tool
description: "Breaks an oversized Vue single-file component into composables and focused child components without changing its props or emits, with each new file complete and a note on why every piece moved. Use when a Vue single-file component has grown past a few hundred lines and needs its logic pulled into composables and its template split into child components. Do not use for scaffolding a new component, fixing a bug in place, or formatting loose pieces into a single file. Related topics: coding, vue."
---

# Vue Component Refactoring Tool

Breaks an oversized Vue single-file component into composables and focused child components without changing its props or emits, with each new file complete and a note on why every piece moved.

## When to use

Use this skill when a Vue single-file component has grown past a few hundred lines and needs its logic pulled into composables and its template split into child components. Do not use it for scaffolding a new component, fixing a bug in place, or formatting loose pieces into a single file.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Map the component's concerns (fetching, form state, derived values, handlers) to the template regions that use them; every concern has an owner.
3. Extract each template-free stateful concern into a composable returning refs and functions, testable without mounting.
4. Extract each template region with its own data into a child component at the chosen granularity, using props down and emits up.
5. Keep the parent's props, emits, and exposed methods byte-identical and re-split any file over the line limit.
6. Emit one block per file with its path and a header comment, then list what moved where and anything not preserved.

## Inputs

- **Original SFC code** (longer free text)
- **Target style** (choose one: Vue 3 script setup, Vue 3 Composition API with setup(), Vue 2 Options API)
- **Max lines per component** (number from 50 to 400)
- **Extract logic into composables** (choose one: Yes, No)
- **File naming convention** (choose one: PascalCase, kebab-case)
- **Component granularity** (choose any: Atomic, Molecular, Organism, Page)
- **Must stay unchanged** (longer free text)

## Output

Fenced code blocks for each new composable, the updated parent, and each child component with file paths, then a short list of moves and anything the split could not preserve.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Vue Component Refactoring Tool

Split the component below into composables and child components.

- Original SFC code: {{Original SFC code}}
- Target style: {{Target style}}
- Max lines per component: {{Max lines per component}}
- Extract logic into composables: {{Extract logic into composables}}
- File naming convention: {{File naming convention}}
- Component granularity: {{Component granularity}}
- Must stay unchanged: {{Must stay unchanged}}

Read the whole component and map its concerns: data fetching, form state, derived values, event handlers, and the template regions that use each. Extract each stateful concern that does not touch the template into a composable (useOrders, useFormValidation) that returns refs and functions, so it can be tested without mounting. Extract each template region with its own props and events into a child component at the granularity requested, passing data down as props and sending changes up as emits rather than reaching into the parent. Keep the parent's external props, emits, and exposed methods identical so no caller changes.

Stay under the line limit per file, and when a child would exceed it, split again. Name files by the chosen convention and import them explicitly. Add a one-line comment at the top of each new file saying what it owns and why it was extracted.

### Output
Return the new composables first, then the updated parent component, then each child component, one fenced block per file with its path, followed by a short list of what moved where and anything the split could not preserve.

## Pitfalls

- Letting a child component reach into the parent's state through refs or provide, which couples the pieces the split was meant to separate.
- Changing a prop name or emit signature on the parent during the split, so every existing caller breaks.
- Extracting a composable that still references template refs, which cannot be tested without mounting the component.
