Setting Up a Monorepo Folder Structure with PNPM Workspaces

We are going to set up a monorepo folder structure with PNPM workspaces.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

  • |

Lesson Transcript

  • [00:00 - 02:44] Welcome to the second module. I hope you're excited about getting started with building mono repos. In the last module we discussed about the challenges having to manage a large number of repositories. This also means we will have to deal with way too many node modules installed in those individual repositories. In this lesson we are going to discuss about a package manager that could solve this issue. pnpm short for plug-and-play package manager is an alternative package manager for node js applications similar to npm short for node package manager and also yarn. Here are some reasons why you might choose to use pnpm. pnpm uses unique approach called content admissible storage to store packages. Instead of duplicating packages in each project it stores them in a global store and creates hard links to the packages in each project. This results in significant disk space savings compared to the other package managers. Fast installation is another benefit that we get from pnpm. Since pnpm uses global store and hard links installing packages is often faster compared to npm and yarn especially when multiple projects share the same dependencies. pnpm uses a partial flat node module structure. In order to manage dependencies pnpm uses the symbolic link and hard link pattern. This means that there are no nested node modules to create for each package which can help with file system performance and reduce the likelihood of hitting file path link limits on certain operating systems. pnpm supports concurrent installations by default. This means that it can download and install multiple packages speeding up the installation speed. pnpm generates a pnpm lock yaml file which is similar to package -lock JSON file with npm or yarn lock file with yarn. pnpm lock file helps to lock down the dependency versions. This ensures that the same versions of dependencies are installed across different environments. pnpm has built in support for an offline mode. Once packages are installed they can be cached locally allowing you to install dependencies even without an internet connection. pnpm is designed to work well with monoripose where multiple packages or projects are managed together. It provides efficient linking and sharing of dependencies across projects within monoripo. In this lesson we learned what pnpm is and why we chose it as our go-to package manager. In the next lesson we will learn how to set up a pnpm workspace