Once you have leveraged Nx's powerful code generation and task running capabilities to build your libraries and applications, you will want to share them with your users.
Nx provides a set of tools to help you manage your releases called nx release
.
We recommend always starting with --dry-run, because publishing is difficult to undo
nx release --dry-run
What makes up a release?
Section titled “What makes up a release?”A release can be thought about in three main phases:
- Versioning - The process of determining the next version of your projects, and updating any projects that depend on them to use the new version.
- Changelog - The process of deriving a changelog from your commit messages or version plan files, which can be used to communicate the changes to your users.
- Publishing - The process of publishing your projects to a registry, such as npm for TypeScript/JavaScript libraries, crates.io for Rust, or Docker registries for container images.
Running Releases
Section titled “Running Releases”The nx release
command is used to run the release process from end to end. It is a wrapper around the three main phases of a release to provide maximum convenience and ease of use.
By default, when you run nx release
it will prompt you for a version keyword (e.g. major, minor, patch) or a custom version number. The release command will then run the three phases of the release process in order: versioning, changelog generation, and publishing.
When trying it out for the first time, you need to pass the --first-release
flag since there is no previous release to compare against for changelog purposes. It is strongly recommended to use the --dry-run
flag to see what will be published in the first release without actually pushing anything to the registry.
nx release --first-release --dry-run
Set Up Your Workspace
Section titled “Set Up Your Workspace”Follow our guides to set up Nx Release for your workspace.
Basic Configuration
Section titled “Basic Configuration”Configure Nx Release in your nx.json
file:
{ "release": { "projects": ["packages/*"] }}
The nx release command is customizable. You can customize the versioning, changelog, and publishing phases of the release process independently through a mixture of configuration and CLI arguments.
See the configuration reference for all available options.
Using the Programmatic API for Nx Release
Section titled “Using the Programmatic API for Nx Release”For maximum control, use the programmatic API to create custom release workflows:
import { releaseChangelog, releasePublish, releaseVersion } from 'nx/release';import * as yargs from 'yargs';
(async () => { const options = await yargs .version(false) // don't use the default meaning of version in yargs .option('version', { description: 'Explicit version specifier to use, if overriding conventional commits', type: 'string', }) .option('dryRun', { alias: 'd', description: 'Whether or not to perform a dry-run of the release process, defaults to true', type: 'boolean', default: true, }) .option('verbose', { description: 'Whether or not to enable verbose logging, defaults to false', type: 'boolean', default: false, }) .parseAsync();
const { workspaceVersion, projectsVersionData } = await releaseVersion({ specifier: options.version, dryRun: options.dryRun, verbose: options.verbose, });
await releaseChangelog({ versionData: projectsVersionData, version: workspaceVersion, dryRun: options.dryRun, verbose: options.verbose, });
// publishResults contains a map of project names and their exit codes const publishResults = await releasePublish({ dryRun: options.dryRun, verbose: options.verbose, // You can optionally pass through the version data (e.g. if you are using a custom publish executor that needs to be aware of versions) // It will then be provided to the publish executor options as `nxReleaseVersionData` // This is not required for the default @nx/js publish executor versionData: projectsVersionData, });
process.exit( Object.values(publishResults).every((result) => result.code === 0) ? 0 : 1 );})();
Learn More
Section titled “Learn More”Configuration & Customization
Section titled “Configuration & Customization”- Release Groups - Version projects independently or together
- Conventional Commits - Automate versioning based on commit messages
- Custom Registries - Publish to private or alternative registries
- CI/CD Integration - Automate releases in your pipeline
- Changelog Customization - Control changelog generation and formatting
- Custom Commit Types - Define custom conventional commit types
- Version Prefixes - Configure version prefix patterns
Workflows
Section titled “Workflows”- Automate with GitHub Actions - Set up automated releases in GitHub workflows
- Release Projects Independently - Manage independent versioning for projects
- Use Conventional Commits - Enable automatic versioning from commits
- Build Before Versioning - Run builds before version updates
References
Section titled “References”- Configuration in
nx.json
- All available options for configuringnx release