@piro0919/next-unused
v1.0.0
Published
CLI to find unused files in your Next.js project. Works with both the app and pages routers.
Maintainers
Readme
@piro0919/next-unused
CLI to find unused files in your Next.js project.
Walks your Next.js dependency graph from the router root (app/, pages/, or both) using madge and reports .ts / .tsx files that no one imports.
Install
npm install --save-dev @piro0919/next-unusedRequires Node 20+.
Usage
{
"scripts": {
"find:unused": "next-unused",
"check:unused": "next-unused --error-on-unused-files"
}
}--error-on-unused-files exits with code 1 when any are found (useful in CI).
Configuration
Drop a config file in your project root. Picked up in this order: next-unused.config.mjs → .js → .json.
// next-unused.config.mjs
export default {
excludeExtensions: [],
excludeFiles: ["middleware.ts"],
includeExtensions: [".ts", ".tsx"],
router: "app", // "app" | "pages" | "both"
srcDir: true,
};| Option | Type | Default | Description |
| ------------------- | ---------------------------- | ------------------- | --------------------------------------- |
| excludeExtensions | string[] | [] | Skip files ending with any of these. |
| excludeFiles | string[] | ["middleware.ts"] | Skip files whose path contains any. |
| includeExtensions | string[] | [".ts", ".tsx"] | Only consider files with these endings. |
| router | "app" \| "pages" \| "both" | "app" | Which router to scan as the graph root. |
| srcDir | boolean | true | Whether your project uses src/. |
Programmatic API
import { findUnusedFiles, loadConfig } from "@piro0919/next-unused";
const config = await loadConfig();
const unused = await findUnusedFiles({ config });License
MIT
