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:

hello: echo "Hello, world!"

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