Skills2026年4月14日·1 分钟阅读

Nx — Smart Monorepos and Fast CI for JavaScript and Beyond

Nx is a build system and monorepo tool with first-class support for JavaScript, TypeScript, Go, Python, Java, and more. It offers computation caching, affected commands, task orchestration, and distributed execution — scaling from small repos to Google-sized codebases.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
直接安装命令
npx -y tokrepo@latest install dc0a4fee-37be-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
Nx provides computation caching, affected commands, task orchestration, and distributed execution for monorepos in any language.
§01

What it is

Nx is a build system and monorepo management tool with first-class support for JavaScript, TypeScript, Go, Python, Java, and more. It provides computation caching, affected-only commands, task orchestration with dependency graphs, and distributed execution across CI agents.

It targets development teams managing monorepos of any size, from small multi-package repositories to large enterprise codebases with hundreds of projects. Nx works as a standalone tool or integrates with existing package managers and build tools.

§02

How it saves time or tokens

Nx caches task outputs (builds, tests, lints) locally and remotely. If code has not changed, Nx replays the cached result instead of re-running the task. The 'affected' command identifies which projects are impacted by a code change and only runs tasks for those projects. These two features together can reduce CI times by 50-90% on large monorepos.

§03

How to use

  1. Install Nx: npx create-nx-workspace@latest for a new workspace, or npx nx init to add Nx to an existing repo.
  2. Define projects and their targets in project.json or package.json files.
  3. Run tasks with npx nx run <project>:<target> or use npx nx affected --target=test to only test changed projects.
§04

Example

# Create a new Nx workspace
npx create-nx-workspace@latest myorg --preset=ts

# Run tests only for affected projects
npx nx affected --target=test --base=main

# Build all projects with caching
npx nx run-many --target=build --all

# Visualize the dependency graph
npx nx graph
§05

Related on TokRepo

§06

Common pitfalls

  • Nx cache invalidation depends on correct input/output configuration. Misconfigured task inputs cause stale cache hits that produce incorrect results.
  • Adding Nx to an existing large repo requires upfront effort to define project boundaries and dependency relationships correctly.
  • Remote caching (Nx Cloud) requires a connection to Nx's cloud service or a self-hosted cache server. Without remote caching, CI agents cannot share cache entries.

常见问题

Does Nx only work with JavaScript and TypeScript?+

No. Nx supports any language or tool that can be invoked from the command line. It has first-class plugins for JavaScript, TypeScript, React, Angular, Node, Go, Python, and Java. You can also define custom executors for any build tool.

How does Nx compare to Turborepo?+

Both provide task caching and affected-command detection. Nx has a larger plugin ecosystem, supports more languages natively, includes a project graph visualization tool, and offers distributed task execution. Turborepo is simpler to adopt for JavaScript-only monorepos.

What is Nx Cloud?+

Nx Cloud is Nx's optional remote caching and distributed execution service. It stores task cache entries in the cloud so CI agents and team members can share cached results. It has a free tier for small teams.

Can I use Nx with an existing npm/yarn/pnpm workspace?+

Yes. Running npx nx init in an existing workspace adds Nx on top of your current package manager. Nx reads your existing package.json scripts and enhances them with caching and dependency-aware orchestration.

How does the dependency graph work?+

Nx automatically analyzes imports, package.json dependencies, and configuration to build a project dependency graph. This graph determines build order, enables affected-only commands, and can be visualized in a browser with npx nx graph.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产