nx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nx (Smart, Fast, Extensible Build System)

Nx(智能、快速、可扩展的构建系统)

Version: 22.x (2025) Tags: Monorepo, Build System, Angular, React, Node
References: Docs — guides, tutorials • GitHubEnterprise Patterns Book
版本: 22.x(2025年) 标签: Monorepo、构建系统、Angular、React、Node
参考资料: 官方文档 —— 包含指南、教程 • GitHub仓库企业模式书籍

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
本部分记录了近期对应版本的API变动:
  • 新增:TypeScript 项目引用 —— 使用现代化TypeScript配置实现更快的构建与类型检查 来源
  • 新增:pnpm catalog 支持 —— 通过pnpm catalog管理单版本策略 来源
  • 新增:Angular Rspack 支持 —— 为Angular项目提供快速打包能力 来源
  • 新增:AI Agent 集成 —— 代码模式可实现更优的LLM上下文管理 来源
  • 新增:多语言工作区 —— 除JS/TS项目外,原生支持Gradle、Maven、.NET项目

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
undefined

Create 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
  • Use
    nx.json
    and
    tsconfig.base.json
    — Enforce consistent settings across projects
  • Use
    @nx/angular:component
    generator — Follow workspace conventions for components
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
    生成器 —— 遵循工作区的组件开发规范