JS
CV

Creating a Monorepo with pnpm Workspaces

May 03, 2024 1 min - read time

To create a monorepo with pnpm, we will need to create a file named pnpm-workspace.yaml inside our repository.

touch pnpm-workspace.yaml

Inside the pnpm-workspace.yaml, we will define our packages. It will have a structure similar to this:

packages:
  - 'app'
  - 'api'
  - 'utils'
  - 'services'

Now we can reference our workspace packages as follows:

{  
	"dependencies": {  
		"@repo/utils": "workspace:*",
		"@repo/services": "workspace:*"  
	}  
}

You can find more details in the pnpm documentation. As we can see, many of the largest frameworks in the market use this approach.

Bonus

To optimize our development workflow, we can integrate Turborepo, a tool that simplifies running scripts across multiple packages.json simultaneously.