Build Before Versioning
In order to ensure that projects are built before the new version is applied to their package manifest, you can use the preVersionCommand
property in nx.json
:
1{
2 "release": {
3 "version": {
4 "preVersionCommand": "npx nx run-many -t build"
5 }
6 }
7}
8
This command will run the build
target for all projects before the version step of Nx Release. Any command can be specified, including non-nx commands. This step is often required when publishing from a custom dist directory, as the dist directory must be built before the version is applied to the dist directory's package manifest.
When using release groups in which the member projects are versioned together, you can use groupPreVersionCommand
and it will be executed before the versioning step for that release group.
1{
2 "release": {
3 "groups": {
4 "my-group": {
5 "projects": ["my-lib-one", "my-lib-two"],
6 "version": {
7 "groupPreVersionCommand": "npx nx run-many -t build -p my-lib-one,my-lib-two"
8 }
9 }
10 }
11 }
12}
13
The groupPreVersionCommand
will run in addition to the global preVersionCommand
.
Build Before Docker Versioning
In order to ensure that images are built before versioning, use the preVersionCommand
property in the docker
section of nx.json
.
1{
2 "release": {
3 "docker": {
4 "preVersionCommand": "npx nx run-many -t docker:build"
5 }
6 }
7}
8
If preVersionCommand
is not set, the default is npx nx run-many -t docker:build
, which builds all projects with a docker:build
target. You can customize this command to be anything that runs prior to Docker versioning.
When using release groups with Docker, use the groupPreVersionCommand
option to run a command before the versioning step for that group.
1{
2 "release": {
3 "groups": {
4 "my-group": {
5 "projects": ["api", "microservice"],
6 "docker": {
7 "groupPreVersionCommand": "npx nx run-many -t docker:build -p api,microservice"
8 }
9 }
10 }
11 }
12}
13
The groupPreVersionCommand
will run in addition to the global preVersionCommand
for Docker.