Deadcode shows you source files that are not required
npm install deadcodeDeadcode shows you source files that are not required anywhere given entry point scripts.
Deadcode list all files not required anywhere in your project and let you remove them.
#### Dynamic requires
Deadcode will ignore dynamic requires but will provide you with a list of files that contain them.
#### Reassigned requires
Deadcode look for import declarations and calls of the _require_ function. In other word if you assign _require_ to another var and use it to load a dependency, it will not handle it.
```
$ npm add deadcode --save-dev
$ deadcode --list-all
info 5 dependencies found
├─ /Users/dead-code/demo/index.js
├─ /Users/dead-code/demo/a.js
├─ fs
├─ /Users/dead-code/demo/b.js
└─ /Users/dead-code/demo/c.js
warning 1 files with dynamic dependencies found
└─ /Users/dead-code/demo/a.js
warning 1 ignored dependencies found
└─ /Users/dead-code/node_modules/@babel/core/lib/index.js
success 0 unparsed dependencies found
success 0 unresolved dependencieswarning 1 dead files found
└─ /Users/dead-code/demo/d.js
You can get help with:
``
$ deadcode --help
- config: config file to use
- entry: array of entry point files
- ignore: array of pattern matching files to ignore
- src: array of pattern matching source files
Options could be:
- provided as command options:
``
$ deadcode --ignore="/node_modules/,/__tests__/"
config
- loaded from file using the command option :`
`
$ deadcode --config=".deadcoderc"
deadcode
- read from the property of your package.json:`
`
{
"deadcode": {
"ignore": ["/node_modules/"]
}
}
You should know that:
- Command options override options in config file.
- Config file options override options in package.json.
- If no entry is provided, the main` property of your package.json will be used.
- resolve dynamic import when possible
- handle reassigned require
- look for dead code in living files