The Nx CLI isn't just another terminal command that accomplishes a predefined task. Developers from Nrwl and the community have created plugins that provide a base level of functionality. In addition, custom generators and executors can be written - expanding the capabilities of the Nx CLI to fit what your organization needs.
The Nx CLI provides commands that fall into three categories:
- Modifying code using generators
- Acting on code using executors
- Understanding the whole codebase
Generators allow developers to automate a code modification task. Generators can be distributed as part of a plugin or developed locally in an Nx workspace. Generators can be composed to create complex workflows and then included in documentation to ensure consistency across the codebase.
Executors are commands that are run that don't affect the actual code. There are built in executors for
build but custom executors can have any name. Nx automatically caches the output of executors so that re-running the same executor with the same code input will complete in seconds. The paid Nx Cloud offering allows this cache to be shared across every developer in your organization.
Nx creates and maintains a dependency graph between projects based on import statements in your code and uses that information to run executors only on the affected projects in a codebase. A visual version of the dependency graph is also available to help developers understand the architecture of the codebase.
Invoke a generator:
nx generate app my-react-app
This command creates a new React app named
Create a workspace generator:
nx generate workspace-generator my-generator nx workspace-generator my-generator
nx migrate latest nx migrate --run-migrations=migrations.json
Run an executor on one project:
nx run my-app:build nx build my-app
Both of these commands build the
my-app application. Custom executors need to use the more verbose
nx run project:target syntax. See the workspace.json documentation for information on configuring executor options.
Run an executor for all affected projects:
nx affected --target=build
This command runs the build executor for all projects that are affected by the current code change.
View the dependency graph:
nx dep-graph nx affected:dep-graph
List installed plugins:
This command lists the currently installed Nx plugins and shows other plugins that are available.