Nx build system and monorepo tools. Advanced task orchestration, generators, and plugins. Use for complex enterprise monorepos with multiple technologies. USE WHEN: user mentions "Nx", "nx.json", "Nx monorepo", "Nx generators", asks about "Nx workspace", "affected commands", "module boundaries" DO NOT USE FOR: Turborepo (use turborepo skill), simple monorepos (Turborepo is simpler), single-package projects

GitHub
安装命令
npx skhub add claude-dev-suite/nx
Markdown
SKILL.md

Nx - Quick Reference

Full Reference: See advanced.md for custom generators, custom executors, remote/self-hosted cache, module boundaries, and CI/CD GitHub Actions setup.

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: nx for comprehensive documentation.

Setup

# New workspace
npx create-nx-workspace@latest my-workspace

# Add to existing repo
npx nx@latest init

Project Structure

my-workspace/
├── nx.json
├── apps/
│   ├── web/project.json
│   └── api/project.json
└── libs/
    ├── ui/project.json
    └── utils/project.json

Configuration (nx.json)

{
  "targetDefaults": {
    "build": {
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"],
      "cache": true
    },
    "test": {
      "inputs": ["default", "^production"],
      "cache": true
    }
  },
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "production": ["default", "!{projectRoot}/**/*.spec.ts"]
  }
}

Running Tasks

# Run target
nx build web
nx test api

# Run for all projects
nx run-many -t build
nx run-many -t build test lint

# Affected (changed since base)
nx affected -t build
nx affected -t test --base=main

# Graph
nx graph

Generators

# Generate application
nx g @nx/react:app my-app
nx g @nx/node:app my-api

# Generate library
nx g @nx/react:lib ui --directory=libs/shared

# Generate component
nx g @nx/react:component button --project=ui

# Dry run
nx g @nx/react:lib feature --dry-run

Plugins

# Add plugin
nx add @nx/react
nx add @nx/node
nx add @nx/vite

Caching

# Skip cache
nx build web --skip-nx-cache

# Clear cache
nx reset

Comparison: Nx vs Turborepo

FeatureNxTurborepo
ConfigurationTypeScriptJSON
GeneratorsAdvancedBasic
Plugins50+Limited
Module boundariesEnforcedManual
Learning curveSteeperLower

When NOT to Use This Skill

  • Simple monorepos - Turborepo has simpler configuration
  • Single package - No need for monorepo tools
  • Quick setup needed - Turborepo is faster to configure

Anti-Patterns

Anti-PatternWhy It's BadCorrect Approach
Ignoring module boundariesTight couplingEnforce with @nx/enforce-module-boundaries
Circular dependenciesBuild failuresUse nx graph to detect and fix
Not using affectedWastes CI timeAlways use nx affected in CI
Missing project tagsCan't enforce constraintsTag all projects properly
No workspace generatorsInconsistent codeCreate generators for common patterns

Quick Troubleshooting

IssueCauseSolution
Module boundary violationWrong importCheck depConstraints in .eslintrc.json
Circular dependencyProjects import each otherUse nx graph, refactor to shared lib
Affected not workingMissing dependenciesCheck implicit dependencies
Cache not workingMissing outputsAdd outputs to target configuration
Build order wrongMissing dependsOnAdd dependsOn: ["^build"]

Production Checklist

  • nx.json configured
  • project.json for each project
  • Module boundaries with tags
  • Affected in CI pipeline
  • Nx Cloud for remote cache
  • Generators for consistency

Reference Documentation

发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

2026年9月24日

分类

未分类

许可证

MIT

源路径

skills/build-tools/nx

默认分支

main

最新提交

9496306

Tree SHA

fe4e2f1