Skip to content

Configuration

Defaults

Knip has good defaults and aims for no or minimal configuration. This is 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. The resulting set of used files is matched against the set of project files to determine which files are unused.

Location

This is where Knip looks for a configuration file:

  • knip.json
  • knip.jsonc
  • .knip.json
  • .knip.jsonc
  • knip.ts
  • knip.js
  • knip in package.json

Use --config path/to/knip.config.json for a different file path.

Customize

If your project structure does not match the default entry and project files, you can customize them. Here’s an example configuration to include .js files in the scripts folder:

knip.json
{
"$schema": "https://unpkg.com/knip@3/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. Project files are used to determine what files are unused.

The values you set override the default values, they are not merged.

In the example above, the file scripts/build.js might be referenced like so:

package.json
{
"name": "my-package",
"scripts": {
"build": "node scripts/build.js"
}
}

In that case, Knip will automatically add it as an entry file. Learn more about this in the next page about entry files.

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. Otherwise, here’s what you might be looking for:

You can always search this website using the search bar at the top (Ctrl+/ or Ctrl+K)

ISC License © 2024 Lars Kappert