Nx Workspace

作者 tech-leads-club120b67676388無授權條款收錄於 2026年10月8日更新於 2026年10月8日

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).

AI 產生的概覽

指導設定、探索與最佳化 Nx 單體倉庫工作區,包含受影響專案分析與 CI/CD 設定。

功能
此技能提供操作 Nx 單體倉庫工作區的說明:列出與檢視專案、讀取解析後的專案設定、執行目標,以及分析受影響的專案。內容也涵蓋工作區架構、函式庫類型、模組邊界、遠端快取,以及使用受影響指令設定 CI/CD 流程。產出的是指引與指令參考,而非檔案或程式碼。
適用情境
適用於建置或探索 Nx 工作區、檢視專案結構或目標、設定專案邊界與快取,或將受影響指令接入 CI/CD 流程。它不用於執行任務或使用產生器產生程式碼。
執行需求
需要 Nx 工作區並可使用 nx 命令列(全域安裝或透過 npx、pnpm、yarn 呼叫);受影響分析需要 git 歷史紀錄。不附帶指令碼,內容為說明文件與參考文件。

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

bash
# List all projectsnx show projects
# Filter by type, pattern, or targetnx show projects --type appnx show projects --projects "apps/*"nx show projects --withTarget build
# Find affected projectsnx 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.

bash
# Get full configurationnx show project my-app --json
# Extract targetsnx 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

bash
# Run specific projectnx build web --configuration=production
# Run affectednx affected -t test --base=main
# View dependency graphnx 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

TypePurposeExample
featureBusiness logic, smart componentsfeature-auth
uiPresentational componentsui-buttons
data-accessAPI calls, state managementdata-access-users
utilPure functions, helpersutil-formatting

Detailed Resources

Configuration: See reference/configuration.md [blocked] for:

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

Commands: See reference/commands.md [blocked] for:

  • Complete command reference
  • Advanced filtering options
  • Common workflows

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

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

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

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

Common Workflows

"What's in this workspace?"

bash
nx show projects --type app  # List applicationsnx show projects --type lib  # List libraries

"How do I run project X?"

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

"What changed?"

bash
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 [blocked].

來源與署名

來源:tech-leads-club/agent-skills位於packages/skills-catalog/skills/(tooling)/nx-workspace提交120b676

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架