pnpm Workspaces

Workspace setup, filtering, recursive execution, deploy flows, and catalogs.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Workspace Basics
Create pnpm-workspace.yaml
cat > pnpm-workspace.yaml <<'YAML'
packages:
  - packages/*
  - apps/*
YAML

# Define the workspace root and included package globs.

Install workspace dependencies
pnpm install

# Inside a workspace, pnpm installs dependencies for all projects by default.

List workspace packages
pnpm -r list --depth 0

# Show workspace packages and their top-level dependencies.

Run command from workspace root only
pnpm -w exec node -p process.cwd()

# Run a command in the workspace root context.

Add a dependency to workspace root
pnpm add -w -D typescript

# Install a dependency into the workspace root package.json.

## Workspace Filter Recipes
Filter exact package
pnpm --filter @acme/api build

# Target a single package by name.

Filter dependents
pnpm --filter @acme/core... test

# Run command on a package and all dependents.

Filter dependencies
pnpm --filter ...@acme/web build

# Run command on a package and all its dependencies.

Filter changed since branch
pnpm --filter "...[origin/main]" test

# Target packages changed since a Git ref and their dependents.

Filter by glob
pnpm --filter "@acme/*" lint

# Target packages that match a glob pattern.

Filter by path
pnpm --filter ./packages/ui... build

# Target packages selected by filesystem path.

## Deploy, Catalogs, and Workspace Features
Deploy one workspace package
pnpm --filter @acme/web deploy dist

# Copy a package with isolated production dependencies to a target directory.

Define a workspace catalog
cat >> pnpm-workspace.yaml <<'YAML'
catalog:
  react: ^18.3.1
  typescript: ^5.8.2
YAML

# Define reusable dependency versions in a workspace catalog.

Publish changed workspace packages
pnpm publish -r

# Publish all packages in a workspace whose new versions are not yet in the registry.

Rebuild all workspace packages
pnpm -r rebuild

# Run rebuild across workspace packages.

Prune node_modules in all packages
pnpm -r prune --prod

# Remove devDependencies from workspace package installs for production prep.

Recommended next

No recommendations yet.