Yarn
yarn was the second package manager to be made after npm. Yarn introduced many innovations at the time including native monorepo support, caching, and lock files.
The first version of Yarn, now known as Yarn Classic, works similar to npm, installing bundled versions of package source code. But the second version of Yarn introduced a strategy called "Plug 'n' Play" as an effort to reduce installation times and use less desk space compared to node_modules
.
Yarn Classic
Setting up workspaces
To create your workspaces, you'll need a workspaces
field in your package.json
:
Now, any directory in your apps
and packages
directories that contains a package.json
will be treated as a workspace.
- docs (Workspace!)
- web (Workspace!)
- logger (Workspace!)
- ui (Workspace!)
Tips and tricks
Interact with a specific workspace
You can run Yarn commands on a specific workspace using the --workspace
command (or -w
, for short).
This will install React to a workspace with the "name": "ui"
in its package.json
.
Figure out where a package is being installed
Package dependencies trees can be hard to debug. Sometimes, you just want to figure out what a package is in your repository in the first place.
This command will show you everywhere in your dependency tree where react
is being brought in and why.