nx-workspace

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nx Workspace Management

Nx工作区管理

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.
探索工作区
nx show projects
nx show project <name> --json

运行任务
nx <target> <project>
(例如:
nx build my-app

受影响项目分析
nx show projects --affected
nx affected -t <target>
注意:如果未全局安装nx,请在命令前添加
npx
/
pnpx
/
yarn
前缀。

Core Commands

核心命令

List and Explore Projects

列出并探索项目

bash
undefined
bash
undefined

List all projects

列出所有项目

nx show 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
nx show projects --type app nx show projects --projects "apps/*" nx show projects --withTarget build

Find affected projects

查找受影响的项目

nx show projects --affected --base=main
undefined
nx show projects --affected --base=main
undefined

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
undefined
重要提示:请始终使用
nx show project <name> --json
获取完整的解析配置。请勿直接读取
project.json
文件——它仅包含部分配置。
bash
undefined

Get full configuration

获取完整配置

nx show project my-app --json
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`
nx show project my-app --json | jq '.targets | keys'

配置模式:

- 工作区:`node_modules/nx/schemas/nx-schema.json`
- 项目:`node_modules/nx/schemas/project-schema.json`

Run Tasks

运行任务

bash
undefined
bash
undefined

Run specific project

运行指定项目

nx build web --configuration=production
nx build web --configuration=production

Run affected

运行受影响项目的任务

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

View dependency graph

查看依赖关系图

nx graph
undefined
nx graph
undefined

Workspace Architecture

工作区架构

workspace/
├── apps/              # Deployable applications
├── libs/              # Shared libraries
│   ├── shared/        # Shared across scopes
│   └── feature/       # Feature-specific
├── nx.json            # Workspace configuration
└── tools/             # Custom executors/generators
workspace/
├── apps/              # 可部署应用程序
├── libs/              # 共享库
│   ├── shared/        # 跨范围共享
│   └── feature/       # 特定功能模块
├── nx.json            # 工作区配置文件
└── tools/             # 自定义执行器/生成器

Library Types

库类型

TypePurposeExample
featureBusiness logic, smart components
feature-auth
uiPresentational components
ui-buttons
data-accessAPI calls, state management
data-access-users
utilPure functions, helpers
util-formatting
类型用途示例
feature业务逻辑、智能组件
feature-auth
ui展示型组件
ui-buttons
data-accessAPI调用、状态管理
data-access-users
util纯函数、工具函数
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
配置:请查看reference/configuration.md了解:
  • nx.json模板及选项
  • project.json结构
  • 模块边界规则
  • 远程缓存设置
命令:请查看reference/commands.md了解:
  • 完整命令参考
  • 高级过滤选项
  • 常见工作流
CI/CD:请查看reference/ci-cd.md了解:
  • GitHub Actions配置
  • GitLab CI搭建
  • Jenkins、Azure Pipelines、CircleCI示例
  • 流水线中的受影响命令
最佳实践:请查看reference/best-practices.md了解:
  • 注意事项(可做与不可做)
  • 完整故障排除指南
  • 性能优化
  • 迁移指南

Common Workflows

常见工作流

"What's in this workspace?"
bash
nx show projects --type app  # List applications
nx 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
"这个工作区里有什么?"
bash
nx show projects --type app  # 列出应用程序
nx show projects --type lib  # 列出库
"如何运行项目X?"
bash
nx show project X --json | jq '.targets | keys'
"哪些内容有变更?"
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.
  • 目标任务未显示:请使用
    nx show project <name> --json
    ,而非直接查看project.json
  • 受影响项目分析功能失效:确保Git历史记录可用(CI中设置
    fetch-depth: 0
  • 缓存问题:运行
    nx reset
    命令
如需详细故障排除,请查看reference/best-practices.md