3 ms·
> With Yarn Workspaces, installing packages across workspaces becomes faster and lighter. Additionally, it prevents package duplication across workspaces and al
by andrew_ 4y ago
> With Yarn Workspaces, installing packages across workspaces becomes faster and lighter. Additionally, it prevents package duplication across workspaces and also makes it possible to create links between directories that depend on each other, ensuring that all directories are consistent in the monorepo.
Nice that they included a footnote about pnpm. Makes me want to write a counter article about using pnpm instead. pnpm is faster than yarn 1 (variable with yarn 2, depending on use) and workspaces are just easier. Lest we forget hoisting and dependency dedupe, which is far and away superior with pnpm.
My pnpm + TS setup is as follows:
- /shared/ directory at root that contains tsconfig.base.json, tsconfig.eslint.json, tsconfig.json (which is only symlinked to, has relative settings for the directories it's linked into)
- tsconfig.json at the root, extending shared/tsconfig.base.json, including all things that an editor might care about
- /packages/ (or /services/) at the root
- /packages/{package}/tsconfig.json -> symlinked to -> /shared/tsconfig.json
This setup allows various editors to validate code in any directory that might have TS (and JS!), editor plugins that use ESLint to have a TS config reference, and allows deployment and/or build processes to operate on individual entities in packages|services without having to build the world. Note that this isn't ideal in monorepos where you want to build the world. In monorepos where I have packages and services, for example, and the services are dependent on the packages build built, I leverage pnpm's recursive script ability with filtering to build some of the world, but not all.
(Happy to answer questions on pnpm monorepos)
- cercatrova 4y agoYarn 3 has a pnpm style linker. It works pretty well, on par with pnpm itself.
- iddan 4y agoYup, we are using it in FlyCode and it works great.
- interstice 4y agoI love the idea of working with pnpm and I currently use yarn workspaces, but last I heard pnpm has issues with next/nuxt, associated ecosystem packages and deployment (Vercel etc). Are there ways around these problems?
- brycelarkin 4y agoNo problem with Next (idk about Nuxt). Checkout the Turborepo starter for how a pnpm/Next monorepo looks.
- forty 4y agoYes, use pnpm ! I should mention meta-updater [1], which is a pnpm tool which allows to keep your various Json config files in sync across the workspace. Pnpm's own mono repo is a good exemple config of meta-updater which keeps TS project references automatically in sync with the actual dependency tree [2] [1] https://github.com/pnpm/meta-updater https://github.com/pnpm/meta-updater [2] https://github.com/pnpm/pnpm/blob/main/.meta-updater/src/index.ts https://github.com/pnpm/pnpm/blob/main/.meta-updater/src/ind...
- chrisweekly 4y agoI like it! Got a blog / writeup to share?