Static analysis for identifying unused files and package usage in React-based codebases.
react-prune is a lightweight CLI tool that analyzes your React, Next.js, and React Native projects to surface unused local files, unused exports, and dependency bloat.
v2.0 Re-written entirely in Bash for speed and simplicity.
-
🔎 Component Usage Detection Find where any component or function is used, including line numbers and file sizes.
-
📦 Package Size & Usage Analysis Checks disk size of dependencies in
node_modulesto spot heavy packages. -
🚫 Unused Dependency Detection Leverages
depcheckto identify dependencies inpackage.jsonthat are completely unused. -
🧹 Unused File & Export Detection Identifies local source files and exports that are never imported anywhere in the project.
Install globally or as a dev dependency:
npm install -g react-prune
# OR
npm install -D react-pruneAlso compatible with yarn and pnpm.
Or run once via npx:
npx react-prune analyzeRun from the root of your project.
Runs a full health check: unused deps, package sizes, unused files, and unused exports.
react-prune analyzeNote: This runs a sequence of bash scripts optimized for Next.js/React projects.
Search for a component, hook, or function to see exactly where it is used and how much it weighs.
react-prune find <Term>Example:
react-prune find ButtonOutput:
🔎 Searching for usage of 'Button'...
✅ Found 5 occurrences:
src/app/page.tsx: 10: <Button>Click me</Button> [5 KB]
src/components/ui/button.tsx: 12: export { Button } [2 KB]
Total: 5 times
🚀 Starting React Prune Analysis...
📦 Checking for unused dependencies...
Unused dependencies
* framer-motion
⚖️ Checking package sizes (top 15 heaviest)...
4.2M lodash
1.1M framer-motion
312K react
🔍 Checking for unused files...
⚠️ Unused file: src/components/OldButton.tsx
⚠️ Unused file: src/utils/deprecated.ts
found 2 unused files.
🔎 Checking for unused exports (heuristic)...
⚠️ Unused export: useOldHook in src/hooks/useMetrics.ts
found 1 unused exports.
The tool is now a collection of focused Bash scripts for maximum performance on Unix-based systems (macOS/Linux).
check_deps.sh: Wrapsdepcheckto find unused NPM packages.check_package_sizes.sh: Usesduto calculatenode_modulesfolder sizes.check_unused_files.sh: Usesfindandgrepto detect unreferenced files (ignoring Next.js pages/layouts).check_unused_exports.sh: Usesgrepto find exported names that don't appear in import statements.
- Platform: Requires a Unix-like environment (macOS, Linux, WSL).
- Heuristic Analysis: Since it uses
grep/regex instead of AST parsing (for speed), extremely complex import aliasing might be missed, but false positives are minimized for standard React/Next.js patterns.
git clone https://github.com/danieljohnson18/react-prune.git
cd react-prune
npm install
npm testTo test locally:
./bin/react-prune analyzeMIT © Daniel Arikawe