Running Custom Commands

You can easily run any command with the Nx toolchain. The main benefit is to make the operation cacheable, distributable as well as being able to use it with Nx's affected commands.

1. Define the terminal command to be run

The command we want to run for each project is:

โฏ

make hello

With this Makefile in the root of the project:

1hello: 2 echo "Hello, world!" 3

2. Update project.json

For each project for which you want to enable make, add a target in its project.json:

project.json
1// ... 2"targets": { 3 "make": { 4 "command": "make hello" 5 } 6 // ... 7} 8

For more information (e.g. how to forward arguments), see the run-commands api doc.

3. Run the command

To run the command, use the usual Nx syntax:

โฏ

nx run my-app:make

or

โฏ

nx make my-app

You can also run the make command for all projects it has been defined on:

โฏ

nx run-many -t make

Or just on a subset of projects that are affected by a given change:

โฏ

nx affected -t make