Nx 任务架构与编排指南
nx-task-guide
关于 Nx 任务架构、编排模式以及如何添加或修改构建任务的参考指南。
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- nx-task-guide
- description
- Reference for Nx task architecture, orchestration patterns, and how to add or modify build tasks
- user-invocable
- false
02 资源文件 2
- 其他agents/gemini.toml2.3 KB
- 参考文档agents/openai.yaml668 B
03 SKILL.md 正文
Nx Task Architecture
This monorepo uses a two-tier task system. Understanding it prevents misconfiguration.
Tier 1: Orchestration Targets (no prefix)
Defined in nx.json targetDefaults. These coordinate work — they have dependsOn but no scripts.
build→ depends on:^build,build:compile,build:api,build:docs,build:manifest,build:readme,build:generate,build:site,build:vitetest→ depends on:build:compile,test:unit,test:vitest,test:snapshotscheck→ depends on:check:format,check:types,check:deps,check:policy,check:references,check:astro,check:svelteci→ depends on:check,build,lint,test:coverage(centralized — update once, all packages inherit)release→ depends on:build,release:license
Packages opt in with a minimal entry in package.json:
"nx": { "targets": { "build": {} } }
Tier 2: Implementation Tasks (with : prefix)
Defined as scripts in each package's package.json. These do the actual work.
Examples: build:compile, build:manifest, test:vitest, check:format
Each has specific inputs and outputs in nx.json for granular caching.
Key Rules
- Never put orchestration logic in package.json scripts — that goes in
nx.jsontargetDefaults - Prefer
affectedoverrun-many—pnpm nx affected -t buildonly builds changed packages - Don't create
project.jsonfiles — all config is centralized innx.json - Implementation tasks cache independently — changing README only reruns
build:readme, notbuild:compile ^prefix means workspace deps first —^buildbuilds dependencies before the current package
Adding a New Task
-
Add the implementation script to the package's
package.json:"scripts": { "build:custom": "your-command" } -
If it should run as part of an orchestration target, add it to
nx.jsontargetDefaults:"build": { "dependsOn": [..., "build:custom"] } -
Add caching config in
nx.jsonif needed:"build:custom": { "inputs": ["production", "^production"], "outputs": ["{projectRoot}/output-dir"] }
Common Commands
pnpm nx affected -t build # Build changed packages
pnpm nx affected -t test # Test changed packages
pnpm nx run cli:build # Build specific package
pnpm nx run-many -t build # Build ALL packages
pnpm nx affected -t build --dry-run # Preview what would run
pnpm nx reset # Clear cache
pnpm nx graph # Visualize dependency graph
Plugin-Inferred Tasks
The @nx/vitest plugin auto-creates test:vitest for packages with vitest.config.ts.
@nx/vite/plugin handles Vite tasks. @nx/js/typescript handles type-check tasks;
its include pattern must match only package-root configs, not test fixtures.
Keep nx and the @nx/* packages on the same version when upgrading.
04 同仓库更多 Skills
unslop
Cut AI tells from any writing.
storytelling
Make sure all prose sentences contribute to a coherent narrative, forming a small story rather than a series of disconnected statements.
stop-slop
Remove AI writing patterns from prose. Use when drafting, editing, or reviewing text to eliminate predictable AI tells.
prose-banlist
A skill that bans certain phrases from being used in prose writing.
ponytail
Lazy senior dev mode: the smallest change that fully solves the task, and a reply a busy human understands in one read. Use on any coding task (writing, fixing, refactoring, reviewing, choosing dependencies) and when the user says "ponytail", "be lazy", "simplest solution", "yagni", or complains about over-engineering or bloat. Levels: lite, full (default), ultra.
ponytail-review
Quality review of a change: is the logic right, is it safe, does it hold under real load, is risky code tested, is it fast enough, and is every line needed. Reads the connected code, not only the diff. Each finding is explained in plain English. Use for "review this", "code review", "review the last commit", "review my PR", "is this over-engineered", /ponytail-review.