All Projects → pacocoursey → next-unused

pacocoursey / next-unused

Licence: other
Find unused files in your Next.js projects

Programming Languages

javascript
184084 projects - #8 most used programming language

next-unused

next-unused is an easy way to find unused files in your Next.js project.

Installation

Install as a devDependency:

$ yarn add next-unused -D

Usage

In package.json, add a script to find unused files:

"scripts": {
  "find:unused": "next-unused"
}

Run the script to list any unused files:

$ yarn find:unused

Configuration

Add a property to your package.json to configure next-unused:

{
  "next-unused": {
    "alias": {},
    "include": [],
    "exclude": [],
    "entrypoints": []
  }
}
Property Type Default Description
debug boolean false turn on debug messages
alias object {} import aliases in webpack format ({ "@components": "components/" })
include string[] ['pages'] list of directories to search through. pages is always included
exclude string[] [] array of RegExp that exclude matching filenames
entrypoints string[] ['pages'] list of directories to use as entrypoints. pages is always included

Example

Your Next.js setup looks like this:

package.json
├─ pages/
│  ├─ index.js
└─ components/
   ├─ button.js
   └─ image.js

And your pages/index.js contains:

import Button from '../components/button'

export default () => {
  return (
    <Button>Click me</Button>
  )
}

Configure next-unused to include the components directory in package.json:

{
  "next-unused": {
    "include": ["components"]
  }
}

Running next-unused will output:

Found 1 unused file:
components/image.js

Credits

Shu and Luc wrote the initial version of this script.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].