Set Up a Monorepo with pnpm Workspace
Problem
Frontend, landing page, mobile apps, and infrastructure code scattered across separate repos makes dependency management painful and sharing common code difficult.
Solution
# pnpm-workspace.yaml
packages:
- frontend
- landing
- android
- ios
- infra
// Root package.json
{
"name": "my-project",
"private": true,
"scripts": {
"dev": "pnpm -F @my-project/frontend dev",
"build": "pnpm -F @my-project/frontend build"
}
}
A single pnpm install at the root installs dependencies for all packages. Use the -F (filter) flag to target specific packages.
Key Points
- A single
pnpm-workspace.yamlfile is all you need. Unlike yarn workspaces, there’s no need to configure anything inpackage.json. - pnpm uses symlinks and content-addressable storage, saving disk space while enforcing strict dependency isolation. It’s structurally better suited for monorepos than npm or yarn.
- Always set
"private": truein the rootpackage.jsonto prevent accidental publishing to npm.