Run App Specific Commands in a Monorepo

Share this video with your friends

Social Share Links

Send Tweet

To run specific commands inside a monorepo we have to type npm run then the name of the command, build. We then add the flag -w for watch mode and specify which package we want to run the build command. In this case, it’s going to be the utils package.

The full command will look like, npm run build -2 @monorepo/utils.

If you want to run all of the commands, you'll need to add the -ws flag.

The full command for running all of our build commands will look like, npm run build -ws.

Alejandro Ñáñez: [0:00] To run in a specific command inside a package of a monorepo, we have to type npm run, then the name of the command, and then we have to add the -w flag. Here, we have to specify in which package we want to run the build command. In this case, it's going to be in utils.

[0:20] Here, you can see that we are running the build script inside a utils package of the monorepo. If what we want is to run the build command across all the packages in the monorepo, we will have to add the -ws flag.

[0:36] Now that the command has ended, we can see that we are running build in the block project first, then we are running build in the dashboard project, and then we are running build inside the utils project.

[0:49] To recap. Running commands inside an npm workspaces monorepo is easy. We just have to type npm run, then the name of the command, and then we can add the -w flag to specify where we want to run that command, or we can add the -ws flag to run that command across all the packages in the monorepo.