Use Nx run-many to Run Commands in Multiple Projects

Share this video with your friends

Send Tweet
Published 4 months ago
Updated 3 weeks ago

You can run multiple projects using the run-many command from Nx and setting a --target flag with the command you want to run.

For example npx nx run-many --target=build

Instructor: [0:00] We cannot just run a single commands by using nx, let's say, build and then specifying the project such as shared UI, but we can also run a command against multiple projects or all projects in the workspace. [0:12] Similar to the pnpm run -r build, which would run to build command in our projects, the equivalent in Nx would be to use the run-many. We would write something like nx run-many, then we give it a target, which in this case is build or could also be test depending on what you want to run. If we don't provide any parameter, it will just run the build for all the projects.

[0:37] We can also pass the projects in. We could say shared-ui, comma, and some other project if we would have some. For instance, if we use the run-many just on the shared-ui, you can see it just runs on that single one. This is a very useful way to filter out some of the project and running commands against those.