A CLI tool to scan, analyze, and optionally remove unused UI components across modern web frameworks such as React, Vue, Svelte, Solid, and others. Designed for monorepos, design systems, or frontend codebases with stale components, this tool identifies unused components and enables safe cleanup.
.tsx
, .jsx
, .vue
, .svelte
, .js
, and more.componentpruneignore
Install globally with npm:
npm install -g component-prune
Or run directly with npx:
npx component-prune
component-prune [path] [options]
Flag | Description | Default |
---|---|---|
path |
Directory to scan for components | . |
--remove |
Automatically delete unused components | false |
--verbose |
Show used components in output | false |
--json <path> |
Output results as a JSON report to specified path | null |
-V, --version |
Display version number | |
-h, --help |
Display help message |
Recursively searches for files following UI component naming conventions (e.g., PascalCase.tsx
, Component.vue
).
Supported file extensions: .tsx
, .ts
, .jsx
, .js
, .vue
, .svelte
Checks each scanned component to determine if it is imported or referenced within the project.
When the --remove
flag is used, the tool safely deletes unused component files.
By default, ignores common folders: node_modules
, .next
, dist
, build
, .vercel
, .output
.
Customize ignored paths by adding a .componentpruneignore
file in the project root.
Use the --json
option to save results in JSON format:
{
"used": [{ "filePath": "...", "name": "Button", "extension": ".tsx" }],
"unused": [{ "filePath": "...", "name": "OldHeader", "extension": ".vue" }]
}
Import and use component-prune as a Node module:
scanComponents(rootDir, ignorePatterns)
: Scans and returns likely component filesanalyzeUsage(components, rootDir)
: Returns { used, unused }
arraysremoveUnused(unused: ComponentFile[])
: Deletes specified unused component filesloadIgnorePatterns(rootDir)
: Loads ignore rules from .componentpruneignore
writeJSONReport(used, unused, outputPath)
: Writes a JSON summary to filecomponent-prune/
├── bin/
│ └── index.ts # CLI entry point
├── src/
│ ├── scanner.ts # Component scanner
│ ├── usageAnalyzer.ts # Usage analyzer
│ ├── remover.ts # Auto-removal logic
│ ├── config.ts # Ignore file loader
│ └── utils.ts # Helpers (writeJSONReport, etc)
│ └── types.ts # Component type
component-prune src/components --remove --json ./prune-report.json
This command:
src/components
directoryprune-report.json
Unused components (1):
- src/components/Testing.tsx
JSON report saved to ./prune-report.json
Unused components deleted.
--verbose
:component-prune src/components --verbose
Used components (1):
- src/components/Icons.jsx
Unused components (1):
- src/components/Testing.tsx
MIT License © 2025
Developed by Chimezie Innocent
Contributions are welcome! Submit pull requests, open issues, or suggest features.