Monorepo with PNPM workspace
Monorepo ?
Monorepo is single repository with many project or packages (library or modules), you can reuse code as package.
en.wikipedia.org/wiki/Monorepo has good explaination for Monorepo including advantages and disadvantages.
Monorepo with PNPM workspace
PNPM only need pnpm-workspace.yaml
on your root repository alongside packages.json
, with array path to directory in packages
property.
NOTE: apps/*
and packages/*
is very popular monorepo structure, where apps/*
is projects directory and packages/*
is reusable code.
All you need just create directory inside packages
list, change directory to it, and do pnpm init
.
List all workspaces
List all workspaces in JSON format.
Command specific workspace
Run command on specific workspace using flag --filter
following with name
in package.json
.
NOTE: PNPM use name
property in package.json
to filter workspace, so make sure ever name
in package.json
is unique.
Add local dependency
Add local dependency using flag --workspace
to only adds the new dependency if it is found in the workspace.
Project example
