Run Commands with Nx

Share this video with your friends

Social Share Links

Send Tweet

Nx provides you with a more convenient syntax to run commands within your workspace projects.

Either nx <target> <project> or nx run <project>:<target> will work, but usually the first one is more convenient to use.

Instructor: [0:00] Now, we could actually use Nx to issue commands against our pnpm workspace packages. Rather than running something like pnpm. That's just filter shared-ui build, Nx uses a syntax which is the following. It is always Nx then the target that we want to run -- in this case, build, for instance -- and then the project that we want to run. [0:22] Or alternatively, we could also use Nx run and then project:target. This is really what you prefer. Usually, this is the easier syntax.

[0:34] To test this out, we could just run Nx, and I just prefix it here with npx or pnpx to reference the local package that lives here in that Node module's folder. I could also install it globally, but I use here npx Nx and then we want to run the build for the shared UI, for instance. You can see how it runs that build.

[0:56] Similarly, that will work for my remix app. You can see Nx already figures out where those packages are, where the specific build command is located by looking at the package.json scripts, and so then runs exactly those scripts which are in here.