Back to the blog

Creating a Monorepo with pnpm Workspaces

To create a monorepo with pnpm, you need to configure a pnpm-workspace.yaml file and define the packages to be used in the project.

Juliano Sirtori
1 min read

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

shell
touch pnpm-workspace.yaml

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

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

Now we can reference our workspace packages as follows:

json
{  
	"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.

Liked it? Leave a reaction

Be the first to react

Let's talk?

Questions, suggestions or a different approach? Leave a comment.

Comments via GitHub. Loaded only when you open them.