跳到正文
Skillpedia
部署与云(DevOps)7.1k · #13573

nx-run-tasks

它能做什么

这个技能在 Nx 工作区中运行常见的开发任务,例如构建、测试和代码检查。适合在单体仓库中工作、并希望快速运行正确任务的开发者。

适用场景

  • ✓当你想在 Nx 工作区中为某个项目运行测试、构建或代码检查时。
  • ✓当你想在许多项目上运行任务,或只运行受某项改动影响的项目时。
  • ✓当你需要启动某个项目的开发服务器时。

技能链接

https://github.com/tech-leads-club/agent-skills/blob/main/packages/skills-catalog/skills/(tooling)/nx-run-tasks/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/tech-leads-club/agent-skills/blob/main/packages/skills-catalog/skills/(tooling)/nx-run-tasks/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“你能只为这次改动所影响的项目,在这个 Nx 工作区中运行测试吗?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会先检查每个项目拥有哪些任务,然后用正确的 Nx 命令运行单个任务、一组任务,或受影响的项目。它可以把运行限制在特定项目,并控制并行运行的数量。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

You can run tasks with Nx in the following way.

Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Look at the package.json or lockfile to determine which package manager is in use.

For more details on any command, run it with --help (e.g. nx run-many --help, nx affected --help).

Understand which tasks can be run

You can check those via nx show project <projectname> --json, for example nx show project myapp --json. It contains a targets section which has information about targets that can be run. You can also just look at the package.json scripts or project.json targets, but you might miss out on inferred tasks by Nx plugins.

Run a single task

nx run <project>:<task>

where project is the project name defined in package.json or project.json (if present).

Run multiple tasks

nx run-many -t build test lint typecheck

You can pass a -p flag to filter to specific projects, otherwise it runs on all projects. You can also use --exclude to exclude projects, and --parallel to control the number of parallel processes (default is 3).

Examples:

  • nx run-many -t test -p proj1 proj2 — test specific projects
  • nx run-many -t test --projects=*-app --exclude=excluded-app — test projects matching a pattern
  • nx run-many -t test --projects=tag:api-* — test projects by tag

Run tasks for affected projects

Use nx affected to only run tasks on projects that have been changed and projects that depend on changed projects. This is especially useful in CI and for large workspaces.

nx affected -t build test lint

By default it compares against the base branch. You can customize this:

  • nx affected -t test --base=main --head=HEAD — compare against a specific base and head
  • nx affected -t test --files=libs/mylib/src/index.ts — specify changed files directly

Useful flags

These flags work with run, run-many, and affected:

  • --skipNxCache — rerun tasks even when results are cached
  • --verbose — print additional information such as stack traces
  • --nxBail — stop execution after the first failed task
  • --configuration=<name> — use a specific configuration (e.g. production)
常见问题

我需要安装 Nx 吗?

不一定。智能体可以根据锁文件使用 npx、pnpx 或 yarn。

它如何找到可用的任务?

它借助 Nx 读取项目配置,其中也包括由插件推断出的任务。

它用于代码生成吗?

不是。代码生成由另一个单独的 Nx 生成器技能负责。

详情

作者的原始描述

Execute build, test, lint, serve, and other tasks in an Nx workspace using single runs, run-many, and affected commands. Use when user says "run tests", "build my app", "lint affected", "serve the project", "run all tasks", or "nx affected". Do NOT use for code generation (use nx-generate) or workspace configuration (use nx-workspace).

repo: tech-leads-club/agent-skills

热度

GitHub 星标
7.1k
排名
#13573
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能