-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
128 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/docs/src/content/docs/typescript/unused-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
title: Unused dependencies | ||
description: Find and remove unused dependencies with Knip | ||
prev: false | ||
next: false | ||
--- | ||
|
||
One of Knip's core features is finding unused dependencies in your JavaScript | ||
and TypeScript projects. And it comes with many more features to remove clutter | ||
and keep your projects in great shape. | ||
|
||
## Why are unused dependencies a problem? | ||
|
||
Having unused dependencies in your `package.json` is an issue for various | ||
reasons: | ||
|
||
- They might end up in the final production bundle, increasing size and load | ||
times for end users. | ||
- They waste space in `node_modules` and add to the installation time of the | ||
project. | ||
- They slow down tooling such as linters and bundlers that analyze dependencies. | ||
- They are confusing and noisy in `package.json`. | ||
- They cause unnecessary extra work when managing and upgrading dependencies. | ||
- They can cause version conflicts with other dependencies in use. | ||
- They can cause false security alerts. | ||
- They might have restrictive licenses and make your project subject to theirs. | ||
- They usually come with transitive dependencies that have the same issues. | ||
|
||
## How do I find unused dependencies? | ||
|
||
Use Knip to find and remove unused dependencies. It also finds dependencies that | ||
are missing in `package.json` and has a lot more features to keep your | ||
JavaScript and TypeScript projects tidy. | ||
|
||
It's easy to [get started](../overview/getting-started.mdx) and make package | ||
management easier and more fun! | ||
|
||
<div style="display: flex; justify-content: center; margin: 4rem auto;"> | ||
<img src="/logo.svg" alt="Logo of Knip, to find unused files, dependencies and exports" class="logo-border" /> | ||
</div> | ||
|
||
## How does Knip identify unused dependencies? | ||
|
||
Knip works by analyzing `package.json` files, source code and configuration | ||
files for other tooling in the project to find unused and missing dependencies. | ||
Knip has many heuristics, [plugins](../reference/plugins.md) and | ||
[compilers](../features/compilers.md) to fully automate the process. | ||
|
||
## Can Knip remove unused dependencies? | ||
|
||
Yes, Knip can automatically remove unused dependencies for you. Add the `--fix` | ||
argument to [auto-fix](../features/auto-fix.mdx) and remove unused dependencies | ||
from `package.json`. | ||
|
||
## Can Knip detect missing dependencies? | ||
|
||
Yes, Knip detects missing dependencies. It analyzes `package.json` files, and | ||
reports packages that are missing. They should be added to `package.json` to | ||
avoid relying on transitive dependencies that can cause version mismatches and | ||
breakage. | ||
|
||
## Does Knip work with monorepos? | ||
|
||
Yes, Knip has first-class support for | ||
[monorepos and workspaces](../features/monorepos-and-workspaces.md). It analyzes | ||
all workspaces in the project and understands their relationship. | ||
|
||
For instance, if a dependency is listed in the root `package.json` it does not | ||
need to be listed in other workspaces. Except if you enable `--strict` checking. | ||
|
||
## Does Knip separate dependencies and devDependencies? | ||
|
||
Yes, Knip understands the difference between dependencies and devDependencies. | ||
It has a [production mode](../features/production-mode.md) to focus on | ||
production code only and find dead code and dependencies that would otherwise | ||
only be referenced by tests and other tooling. This allows you to remove both | ||
unused exported code and their tests. | ||
|
||
## Does Knip work with my package manager? | ||
|
||
Yes, Knip works with any package manager: npm, pnpm, Bun and Yarn are all | ||
supported. It's easy to [get started](../overview/getting-started.mdx) with any | ||
package manager. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters