跳到正文
Skillpedia
部署与云(DevOps)41k · #6682

nx-workspace-patterns

它能做什么

这个指南能帮你用 Nx 工具整理大型软件项目。它会教你如何把代码拆分成更小、可复用的部分,从而优化构建和测试的时间。

适用场景

  • ✓开始一个新的大型项目时。
  • ✓项目开始变得混乱时。
  • ✓想加快测试和构建速度时。

技能链接

https://github.com/wshobson/agents/blob/main/plugins/developer-essentials/skills/nx-workspace-patterns/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/wshobson/agents/blob/main/plugins/developer-essentials/skills/nx-workspace-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我怎样组织大型项目,才能让它运行得更快?”

每周 5 个新技能,1 分钟读完。

工作原理

它采用一种结构,把代码分成应用(可以直接运行的部分)和库(可以被反复使用的部分)。这样 Nx 就能准确知道哪些内容需要重新构建或测试,从而节省时间。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Nx Workspace Patterns

Production patterns for Nx monorepo management.

When to Use This Skill

  • Setting up new Nx workspaces
  • Configuring project boundaries
  • Optimizing CI with affected commands
  • Implementing remote caching
  • Managing dependencies between projects
  • Migrating to Nx

Core Concepts

1. Nx Architecture

workspace/
├── apps/              # Deployable applications
│   ├── web/
│   └── api/
├── libs/              # Shared libraries
│   ├── shared/
│   │   ├── ui/
│   │   └── utils/
│   └── feature/
│       ├── auth/
│       └── dashboard/
├── tools/             # Custom executors/generators
├── nx.json            # Nx configuration
└── workspace.json     # Project configuration

2. Library Types

Type Purpose Example
feature Smart components, business logic feature-auth
ui Presentational components ui-buttons
data-access API calls, state management data-access-users
util Pure functions, helpers util-formatting
shell App bootstrapping shell-web

Templates and detailed worked examples

Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.

Best Practices

Do's

  • Use tags consistently - Enforce with module boundaries
  • Enable caching early - Significant CI savings
  • Keep libs focused - Single responsibility
  • Use generators - Ensure consistency
  • Document boundaries - Help new developers

Don'ts

  • Don't create circular deps - Graph should be acyclic
  • Don't skip affected - Test only what changed
  • Don't ignore boundaries - Tech debt accumulates
  • Don't over-granularize - Balance lib count
常见问题

什么是“apps”和“libs”?

“apps”是项目中可以运行或部署的部分,比如一个网站或一项服务。“libs”是可以被多个“apps”或其他“libs”使用的代码模块,比如 UI 组件或工具函数。

为什么组织代码很重要?

在大型项目中,如果不好好组织代码,很快就会变得一团糟。合理的组织方式便于查找内容、复用代码,还能确保只有被修改的部分才需要测试,让开发更快、更高效。

什么是“循环依赖”?

指 A 部分的代码需要 B 部分,而 B 部分又反过来需要 A 部分,形成一个闭环。这会让系统产生混乱,应当避免,以保持项目结构清晰。

详情

作者的原始描述

Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.

repo: wshobson/agents

热度

GitHub 星标
41k
排名
#6682
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能