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

nx-workspace

它能做什么

这个技能帮助设置和理解 Nx 单体仓库工作区。适合在同一个仓库中管理多个应用和库、并希望构建更快的开发者和技术负责人。

适用场景

  • ✓当你正在设置 Nx,或需要理解单体仓库的结构时。
  • ✓当你想设置项目边界,或查看哪些项目相互依赖时。
  • ✓当你想通过受影响命令和构建缓存加速 CI 时。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“你能解释一下我的 Nx 工作区是如何组织的,并建议如何加快我们的 CI 构建吗?”

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

工作原理

智能体会列出各个项目,使用 Nx 命令读取它们完整解析后的配置,并梳理出结构。然后,它会就边界、缓存以及受影响命令提出修改建议,以加快流水线。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Nx Workspace Management

Quick Start

Exploring workspace: nx show projects and nx show project <name> --json
Running tasks: nx <target> <project> (e.g., nx build my-app)
Affected analysis: nx show projects --affected or nx affected -t <target>

Note: Prefix commands with npx/pnpx/yarn if nx isn't installed globally.

Core Commands

List and Explore Projects

# List all projects
nx show projects

# Filter by type, pattern, or target
nx show projects --type app
nx show projects --projects "apps/*"
nx show projects --withTarget build

# Find affected projects
nx show projects --affected --base=main

Get Project Information

Critical: Always use nx show project <name> --json for full resolved configuration. Do NOT read project.json directly - it contains only partial configuration.

# Get full configuration
nx show project my-app --json

# Extract targets
nx show project my-app --json | jq '.targets | keys'

Configuration schemas:

  • Workspace: node_modules/nx/schemas/nx-schema.json
  • Project: node_modules/nx/schemas/project-schema.json

Run Tasks

# Run specific project
nx build web --configuration=production

# Run affected
nx affected -t test --base=main

# View dependency graph
nx graph

Workspace Architecture

workspace/
├── apps/              # Deployable applications
├── libs/              # Shared libraries
│   ├── shared/        # Shared across scopes
│   └── feature/       # Feature-specific
├── nx.json            # Workspace configuration
└── tools/             # Custom executors/generators

Library Types

Type Purpose Example
feature Business logic, smart components feature-auth
ui Presentational components ui-buttons
data-access API calls, state management data-access-users
util Pure functions, helpers util-formatting

Detailed Resources

Configuration: See reference/configuration.md for:

  • nx.json templates and options
  • project.json structure
  • Module boundary rules
  • Remote caching setup

Commands: See reference/commands.md for:

  • Complete command reference
  • Advanced filtering options
  • Common workflows

CI/CD: See reference/ci-cd.md for:

  • GitHub Actions configuration
  • GitLab CI setup
  • Jenkins, Azure Pipelines, CircleCI examples
  • Affected commands in pipelines

Best Practices: See reference/best-practices.md for:

  • Do's and don'ts
  • Complete troubleshooting guide
  • Performance optimization
  • Migration guides

Common Workflows

"What's in this workspace?"

nx show projects --type app  # List applications
nx show projects --type lib  # List libraries

"How do I run project X?"

nx show project X --json | jq '.targets | keys'

"What changed?"

nx show projects --affected --base=main

Quick Troubleshooting

  • Targets not showing: Use nx show project <name> --json, not project.json
  • Affected not working: Ensure git history available (fetch-depth: 0 in CI)
  • Cache issues: Run nx reset

For detailed troubleshooting, see reference/best-practices.md.

常见问题

为什么不直接读取 project.json?

该技能说明,project.json 只包含部分设置,完整的配置需要由 Nx 得出。

它能显示依赖图吗?

可以。它可以通过 Nx 命令显示项目依赖图。

它也会运行任务吗?

运行任务是另一个单独的技能,但你要求时它也可以运行某个目标。

详情

作者的原始描述

Configure, explore, and optimize Nx monorepo workspaces. Use when setting up Nx, exploring workspace structure, configuring project boundaries, analyzing affected projects, optimizing build caching, or implementing CI/CD with affected commands. Keywords — nx, monorepo, workspace, projects, targets, affected. Do NOT use for running tasks (use nx-run-tasks) or code generation with generators (use nx-generate).

repo: tech-leads-club/agent-skills

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能