@berenddeboer/nx-knip

中文文档
1.1.0发布于 2026/03/03MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 5944

Nx self-inferring plugin for Knip - find unused dependencies, exports, and files

原始使用文档
文档目录9 节
  1. Install
  2. Usage
  3. Plugin Setup
  4. Running Knip
  5. Executor Options
  6. strict
  7. env
  8. How it works
  9. Learn More

@berenddeboer/nx-knip

A self-inferring Nx plugin for Knip - find unused dependencies, exports, and files in your JavaScript/TypeScript projects.

Install

Install both the plugin and knip:

npm
npm install --save-dev @berenddeboer/nx-knip knip
pnpm
pnpm add --save-dev @berenddeboer/nx-knip knip
yarn
yarn add --dev @berenddeboer/nx-knip knip
bun
bun add -D @berenddeboer/nx-knip knip

Usage

Plugin Setup

Add the plugin to your nx.json:

{
  "plugins": [
    {
      "plugin": "@berenddeboer/nx-knip",
      "options": {
        "targetName": "knip"
      }
    }
  ]
}

This will automatically add a knip target to all projects in your workspace.

Running Knip

Run knip for a single project:

nx knip my-project

Run knip for all affected projects:

nx affected -t knip

Or run it for all projects:

nx run-many -t knip

Executor Options

strict

Enable strict mode (implies --production). Defaults to false. When enabled, knip will:

  • Verify isolation: workspaces should use strictly their own dependencies
  • Include peerDependencies when finding unused or unlisted dependencies
  • Report type-only imports listed in dependencies

You can enable it for all projects via the plugin options in nx.json:

{
  "plugins": [
    {
      "plugin": "@berenddeboer/nx-knip",
      "options": {
        "targetName": "knip",
        "strict": true
      }
    }
  ]
}

Or per-project in project.json:

{
  "targets": {
    "knip": {
      "options": {
        "strict": true
      }
    }
  }
}

env

Set environment variables for the knip process. This is useful when knip loads .ts files that throw on missing environment variables - you can provide dummy values so knip can analyze the files without errors.

Configure via targetDefaults in nx.json:

{
  "targetDefaults": {
    "knip": {
      "options": {
        "env": {
          "SQLITE_DATABASE_PATH": "/tmp/knip-dummy.db",
          "PF_ORG": "examples/demo"
        }
      }
    }
  }
}

Or per-project in project.json:

{
  "targets": {
    "knip": {
      "options": {
        "env": {
          "DATABASE_URL": "postgres://localhost/dummy"
        }
      }
    }
  }
}

The provided environment variables are merged with the current process.env, so existing variables are preserved and the specified ones are added or overridden.

How it works

This plugin runs knip --workspace {projectRoot} from the workspace root for each project. This means:

  1. It uses the --workspace flag to focus on a specific workspace
  2. The workspace root knip.json configuration is used
  3. If Bun is installed, the plugin automatically uses knip-bun for significantly better performance

Learn More

版本与发布记录

@berenddeboer/nx-knip 共发布 7 个版本,首次发布于 2025/12/24;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.0latest2026/03/038 个月前
1.0.22026/02/178 个月前
1.0.12026/02/178 个月前
1.0.02026/02/178 个月前
0.1.12025/12/2410 个月前
0.1.02025/12/2410 个月前

关于 @berenddeboer/nx-knip 的常见问题

@berenddeboer/nx-knip 是什么?

Nx self-inferring plugin for Knip - find unused dependencies, exports, and files

如何安装 @berenddeboer/nx-knip?

在项目目录运行 npm install @berenddeboer/nx-knip,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@nx/devkit(^20.6.4 || ^21.0.0 || ^22.0.0)、knip(^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@berenddeboer/nx-knip 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@berenddeboer/nx-knip 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@berenddeboer/nx-knip 可以商用吗?

@berenddeboer/nx-knip 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@berenddeboer/nx-knip 的下载量有多少?

根据 npm 官方下载统计,@berenddeboer/nx-knip 在 2026/10/08 – 2026/11/06 这 30 天内被下载 5,944 次,日均约 198 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@berenddeboer/nx-knip 还在维护吗?

最新版本 1.1.0 发布于 2026/03/03(8 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2025/12/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。