Create the fast working Monorepo with pnpm workspaces and turborepo

Salih Baki Sayer
2 min readOct 18, 2022

--

What is a Monorepo

Monorepo is a single repository that contains multiple applications. Rather then splitting each application in to its own repository, we put all in one. This brings benefits like:

  • Easy code sharing with shared packages and no need to wait for publishing to npm
  • Everybody can see the changes and aware what is going on
  • Most of the big companies, frameworks etc. using this, so it must be good :)

You can think about cons or search for that. I will not waste your time with it.

Why pnpm workspace

Pnpm is fast thangs to using one store for all npm packages and linking when you need that in to your locale package. Basically it has a caching system for packages.

Pnpm workspace is works just fine for most use cases.

Why turbo repo

Dealing with monorepo and mutliple packages that has dependencies to each other needs an optimization for processes like: build, test, lint, codegeneration, deployment etc.

Turbo repo has a turbo.json config file like this.

You are defining the scripts and the dependencies for that scripts.

If you define an input turbo creates a hash with that files, if not it uses all the files in the package.

Also if you define output it caches that output too

What turbo repo does best is;

  • It creates a graph of the dependencies of packages and the scripts
  • Creates hash to check whether inputs are changed
  • If you want it also does the remote caching so you can share cache with your colleagues or pipelines.

Detailed info for pnpm and turbo can be found at their homesites.

Summary

We are refactoring our big single repo application to monorepo with this pnpm and turbo repo. So far everything is good. They both are fast and as we refactor the single package to multiple ones it goes faster.

If you want to create or refactor the existing codebase to a monorepo give them a try.

--

--

Salih Baki Sayer
Salih Baki Sayer

Written by Salih Baki Sayer

Software developer, loves web dev , kendo (3.dan), books and games.

No responses yet