Skip to main content
Code generators are TypeScript functions that accept parameters and automate repetitive development tasks. They help you:
  • Scaffold new applications and libraries with consistent structure
  • Augment existing projects with new capabilities (e.g. adding Storybook)
  • Enforce organization-wide coding standards automatically
Generators are distributed as part of Nx plugins and are invoked with nx generate (or nx g).

Invoke a generator

The syntax is nx g <plugin-name>:<generator-name> [options]:
You can also specify just the generator name and Nx will prompt you to choose from installed plugins that provide a matching generator:

Preview changes before applying

Use --dry-run to see what files would be created or modified without writing any changes to disk:
This is useful for reviewing the impact of a generator before committing to it.

List available generators

To see all generators provided by an installed plugin:
To list all installed plugins and their capabilities:

Interactive mode

When you omit required options, Nx prompts you interactively:
You can also run generators through Nx Console, a VS Code / WebStorm extension that provides a visual form-based interface for finding and running generators. Install it from the VS Code Marketplace.

Build your own generator

You can write custom generators to automate your organization’s specific workflows. A generator is a function with the following signature:
The @nx/devkit package provides utilities for reading/writing files, generating names, running tasks, and more.
1

Create the generator

Scaffold a new local generator using the @nx/plugin generator:
2

Implement the generator function

Edit the generated generator.ts file to implement your logic using @nx/devkit utilities.
3

Run your generator

See the local generators guide for full documentation on building and testing generators.