Configuration
Defaults
Section titled “Defaults”Knip has good defaults and aims for “zero config”. Here’s a simplified version of the default configuration:
{ "entry": ["index.{js,ts}", "src/index.{js,ts}"], "project": ["**/*.{js,ts}"]}Entry files are the starting point for Knip to find more source files and external dependencies.
Location
Section titled “Location”By default, Knip will look for a configuration file with the following names:
knip.jsonknip.jsonc.knip.json.knip.jsoncknip.tsknip.jsknip.config.tsknip.config.jspackage.json(in the"knip"property)
If you want to use a custom file name or path, use the --config flag:
knip --config path/to/knip.jsonCustomize
Section titled “Customize”Your project structure may not match the default entry and project files.
Here’s an example custom configuration to include .js files in the scripts
folder:
{ "$schema": "https://unpkg.com/knip@5/schema.json", "entry": ["src/index.ts", "scripts/{build,create}.js"], "project": ["src/**/*.ts", "scripts/**/*.js"]}If you override the entry file patterns, you may also want to override
project file patterns. The set of project files is used to determine what
files are unused. The project patterns can also be negated to exclude files
from the analysis. See configuring project files for details.
The values you set override the default values, they are not merged.
Knip looks in many places for entry files. Learn more about this in the next page about entry files.
Configuration Options
Section titled “Configuration Options”See configuration file options.
To use JavaScript or TypeScript in the configuration file, see dynamic configuration.
What’s next?
Section titled “What’s next?”The best way to understand Knip and what it can do for you is to read the pages in the “Understanding Knip” sections, starting with entry files.
Want to learn more about some of the main features?
- Working with monorepos & workspaces.
- Learn more about production mode.
Having troubles configuring Knip?
Search this website using the bar at the top (Ctrl+K or ⌘+K).
ISC License © 2024 Lars Kappert