nx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNx (Smart, Fast, Extensible Build System)
Nx(智能、快速、可扩展的构建系统)
Version: 22.x (2025)
Tags: Monorepo, Build System, Angular, React, Node
API Changes
API 变更
This section documents recent version-specific API changes.
-
NEW: TypeScript Project References — Faster builds and type checks using modern TypeScript setup source
-
NEW: pnpm catalog support — Manage single version policy with pnpm catalogs source
-
NEW: Angular Rspack support — Fast bundler for Angular projects source
-
NEW: AI Agent integration — Code mode for better LLM context management source
-
NEW: Polyglot workspaces — Native support for Gradle, Maven, .NET alongside JS/TS projects
Best Practices
最佳实践
- Use domain-based folder structure — Group projects by business domain
libs/
├── auth/
│ ├── feature-login/
│ └── data-access/
├── products/
│ ├── feature-list/
│ └── ui/
└── shared/
├── ui/
└── utils/- Use Nx generators — Scaffold consistent code across workspace
bash
undefined- 采用基于领域的文件夹结构 —— 按业务域对项目进行分组
libs/
├── auth/
│ ├── feature-login/
│ └── data-access/
├── products/
│ ├── feature-list/
│ └── ui/
└── shared/
├── ui/
└── utils/- 使用Nx生成器 —— 在整个工作区生成风格统一的代码
bash
undefinedCreate new library
Create new library
nx g @nx/angular:library --name=shared-data-access --directory=libs/shared/data-access
nx g @nx/angular:library --name=shared-data-access --directory=libs/shared/data-access
Create new feature
Create new feature
nx g @nx/angular:component --name=user-profile --project=my-app
- Use affected commands — Only run tasks on changed projects
```bash
nx affected:build # Build only changed projects
nx affected:test # Test only changed projects
nx affected:lint # Lint only changed projects-
Use shared libraries — Avoid code duplication with common utilities
-
Configure task dependencies — Define how tasks depend on each other in
project.json
json
{
"build": {
"dependsOn": ["^build"]
}
}-
Use Nx Cloud — Enable distributed caching for faster CI
-
Useand
nx.json— Enforce consistent settings across projectstsconfig.base.json -
Usegenerator — Follow workspace conventions for components
@nx/angular:component
nx g @nx/angular:component --name=user-profile --project=my-app
- 使用affected命令 —— 仅对发生变更的项目执行任务
```bash
nx affected:build # Build only changed projects
nx affected:test # Test only changed projects
nx affected:lint # Lint only changed projects-
使用共享库 —— 通过通用工具函数避免代码重复
-
配置任务依赖 —— 在中定义任务之间的依赖关系
project.json
json
{
"build": {
"dependsOn": ["^build"]
}
}-
使用Nx Cloud —— 启用分布式缓存提升CI速度
-
使用和
nx.json—— 在所有项目中强制统一配置tsconfig.base.json -
使用生成器 —— 遵循工作区的组件开发规范
@nx/angular:component