Install Nx to Start Optimizing Your pnpm Workspace

Share this video with your friends

Send Tweet
Published 4 months ago
Updated 2 weeks ago

Even running all your scripts at once will get slow and tedious as your project grows.

That's where Nx come in. Nx will generally optimize the experience with caching and selectively running commands.

Instructor: [0:00] As our PNPM workspace grows, we might want one to optimize some of the things that we do with it. For instance, running PNPM, let's say run -r build every time we push a new change to our repository. Every time we run a PR might not be feasible anymore, simply because it takes so long on our CI system, it will be overwhelming. [0:23] We might want to optimize some of the things in here and leverage things like caching or abilities to only run packages that got changed between the different PRs.

[0:34] One way to do that is by using Nx. Nx is a modern, fast, extensible built system that basically can sit on top of your existing PNPM workspace and do nothing else than providing you things like caching support, things like figuring out what changed and only running commands against that, and in general running tasks in a very efficient manner.

[0:56] Let's see how we can set up Nx on top of our PNPM workspace. For now, all that we need to do is run pnpm add. We need to add Nx package. We want to have it as a dev dependency because we don't really need it at runtime when we deploy our application or libraries. We want to install it at the workspace level, so the very root level package.json.

[1:19] Once Nx is installed, we can see now in the package.json at the root level, we got a new dev dependency. With that we are already set up.