nx — скилл для Claude Code: правила Nx-монорепозитория
Скилл задаёт агенту правила работы с Nx: структура apps и libs, теги, границы модулей, генераторы и кэш. Пригодится, если проект уже собран на Nx.
npx skills add Mindrally/skills --skill nx -a claude-codeЧто делает nx
Скилл описывает, как агент должен вести себя в Nx-воркспейсе. Проекты раскладываются по apps/ и libs/, имена строятся по схеме scope-type-name, родственные библиотеки группируются в feature-папки. Настройки воркспейса живут в nx.json, отдельный проект — в project.json со своим sourceRoot, projectType и списком tags.
Границы модулей держатся на ESLint-правиле @nx/enforce-module-boundaries с depConstraints: приложение может зависеть только от библиотек и утилит, а scope вроде scope:web тянет лишь свой scope и scope:shared. Сборка и тесты кэшируются, affected-команды гоняют задачи только по изменённым проектам. Генераторы вызываются как nx g @nx/react:app my-app, а --dry-run показывает, что изменится, до записи файлов.
Скилл ничего не устанавливает в ваш проект и не правит конфиги сам — это инструкция для агента. Если в воркспейсе нет тегов на проектах, правило границ работать не будет: зависимости проходят без проверок. Советует начать с nx graph, чтобы увидеть текущие связи, и только потом раздавать теги.
Какие задачи решает
- разложить проекты по apps и libs без свалки в одной папке
- запретить приложению тянуть чужой домен через теги
- сгенерировать приложение или библиотеку одной командой
- перестать пересобирать всё и гонять только affected-задачи
- настроить кэш сборки и тестов в nx.json
Примеры запросов агенту
- Сгенерируй React-библиотеку shared-ui-button и добавь теги scope:shared и type:lib
- Проверь project.json и скажи, какие теги мешают правилу границ модулей
- Настрой targetDefaults в nx.json так, чтобы build зависел от сборки зависимостей и кэшировался
Как установить nx
1Через Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a claude-code2Вручную: положить файлы
~/.claude/skills/nx/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/nx/
1Через Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a codex2Вручную: положить файлы
.agents/skills/nx/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a cursor2Вручную: положить файлы
.cursor/skills/nx/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills nx2Вручную: положить файлы
.github/skills/nx/SKILL.md1Через Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a gemini-cli2Командой платформы
gemini skills install https://github.com/Mindrally/skills --path nxВручную: положить файлы
.devin/skills/nx/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add Mindrally/skills --skill nx -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о nx
Как установить nx в Claude?
Выполните npx skills add Mindrally/skills --skill nx -a claude-code. После этого файл скилла лежит в ~/.claude/skills/nx/SKILL.md.
Что делает скилл nx?
Он объясняет агенту, как устроен Nx-воркспейс: структура apps и libs, конфиги nx.json и project.json, генераторы, границы модулей и affected-команды. Агент опирается на эти правила, когда пишет код и правит конфигурацию.
Зачем нужны теги в project.json?
На них держится ESLint-правило @nx/enforce-module-boundaries. Без тегов в depConstraints нечего сравнивать, и запрет на зависимости между доменами не сработает.
Исходный текст
SKILL.md · Apache-2.0
---
name: nx
description: Best practices for Nx monorepo development, project configuration, and code generation
metadata:
maintainer: Mindrally
source: https://github.com/Mindrally/skills
---
# Nx Monorepo Development
You are an expert in Nx, the smart, fast, and extensible build system for monorepos.
## Project Structure
- Organize projects following Nx conventions:
- `apps/` - Application projects (web apps, APIs, mobile apps)
- `libs/` - Library projects (shared code, features, utilities)
- Use consistent naming patterns: `scope-type-name` (e.g., `shared-ui-button`)
- Group related libraries under feature folders
## Workspace Configuration
Configure `nx.json` for workspace-wide settings:
```json
{
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"cache": true
},
"test": {
"cache": true
}
},
"defaultBase": "main"
}
```
- Use `project.json` for project-specific configuration
- Define proper `tags` for enforcing module boundaries
## Project Configuration
Each project should have a `project.json`:
```json
{
"name": "my-app",
"sourceRoot": "apps/my-app/src",
"projectType": "application",
"tags": ["scope:web", "type:app"],
"targets": {
"build": { },
"serve": { },
"test": { }
}
}
```
- Define clear project types: `application` or `library`
- Use tags for enforcing dependency constraints
## Code Generation
- Use Nx generators for consistent code scaffolding:
- `nx g @nx/react:app my-app` - Generate React application
- `nx g @nx/react:lib my-lib` - Generate React library
- `nx g @nx/react:component my-component --project=my-lib` - Generate component
- Create custom generators for project-specific patterns
- Use `--dry-run` to preview changes before execution
## Module Boundaries
Enforce boundaries using ESLint rules:
```json
{
"@nx/enforce-module-boundaries": [
"error",
{
"depConstraints": [
{ "sourceTag": "type:app", "onlyDependOnLibsWithTags": ["type:lib", "type:util"] },
{ "sourceTag": "type:lib", "onlyDependOnLibsWithTags": ["type:lib", "type:util"] },
{ "sourceTag": "scope:web", "onlyDependOnLibsWithTags": ["scope:web", "scope:shared"] }
]
}
]
}
```
- Define clear dependency rules between project types
- Use scopes to separate domain boundaries
## Caching and Performance
- Enable computation caching for faster builds
- Configure Nx Cloud for distributed caching and task execution
- Use affected commands to only run tasks for changed projects:
- `nx affected:build`
- `nx affected:test`
- `nx affected:lint`
- Define proper `inputs` and `outputs` for accurate caching
## Task Execution
- Run tasks with Nx CLI:
- `nx build my-app` - Build specific project
- `nx run-many -t build` - Build all projects
- `nx affected -t test` - Test affected projects
- Use task pipelines for proper dependency ordering
- Configure parallel execution for independent tasks
## Testing Strategy
- Use Jest for unit testing with Nx presets
- Configure Cypress or Playwright for E2E testing
- Implement component testing for UI libraries
- Use `nx affected:test` in CI for efficient test runs
## CI/CD Integration
- Use Nx Cloud for distributed task execution
- Configure GitHub Actions with Nx:
```yaml
- uses: nrwl/nx-set-shas@v4
- run: nx affected -t lint test build
```
- Implement proper caching strategies
- Use `nx-cloud record` for capturing metrics
## Best Practices
- Keep applications thin; move logic to libraries
- Create shared utility libraries for common code
- Use barrel exports (`index.ts`) for clean imports
- Implement proper type exports from libraries
- Document library purposes and public APIs
- Use Nx Console VS Code extension for visual project management
- Leverage the project graph for understanding dependencies: `nx graph`
© Mindrally · Apache-2.0 · Mindrally/skills