Sitemap
Yassir Ben Boubker

Yassir Ben Boubker

Why use pnpm Workspace?

2 min readAug 8, 2026

--

Press enter or click to view image in full size

Think of a pnpm workspace (or a monorepo) as a single main project folder that holds multiple smaller projects or packages inside it.

Instead of opening five different code editors for five different parts of an app, you keep them all under one roof.

🟢 The Real-World Analogy: A Toy Factory

Imagine you are building a LEGO toy company with three departments:

  1. wheels-maker: Builds the wheels.
  2. car-body-maker: Builds the body.
  3. toy-store: Assembles the complete car and sells it to customers.

How traditional NPM handles this:

Every time you make a tweak to wheels-maker, you have to publish it to the internet, then log into toy-store and download the new wheels. It is slow and annoying!

How a pnpm Workspace handles this:

All three departments live inside the same big folder (the “workspace”). When toy-store needs wheels, pnpm links them together locally on your computer. When you change wheels-maker, toy-store instantly sees the update—no publishing or downloading required.

🔑 Key Concepts on the Page Explained Simply

1. The pnpm-workspace.yaml File

This is just a simple map at the root of your folder that tells pnpm: “Hey, look inside the /packages folder, all those subfolders are part of our team!"

2. The workspace: Protocol

In your sub-project’s package.json, you tell pnpm where to get dependencies.

Get Yassir Ben Boubker’s stories in your inbox

Join Medium for free to get updates from this writer.

Normally, you write:

"dependencies": {
"wheels-maker": "^1.0.0"
}

Problem: pnpm might try to go to the public internet registry to download wheels-maker.

With pnpm workspaces, you write:

"dependencies": {
"wheels-maker": "workspace:*"
}

Meaning:

ONLY use the wheels-maker sitting right here in my local workspace folder, do NOT download anything from the internet!

3. Automatic Publishing Cleanup

When you are finally ready to release toy-store to the world, running pnpm publish automatically converts workspace:* back into a standard version number (like 1.0.0) so that other developers on the internet can use your app normally.

💡 Why use a Workspace?

  • Shared Code: Reusing UI components, utility functions, or database tools across multiple apps without copying and pasting.
  • Speed: pnpm installs shared packages once and links them everywhere, saving hard drive space and install time.
  • One-Command Controls: You can run tests or build steps across all sub-projects at once from the root folder.

--

--