Yarn
# Modify `/etc/hosts`
npm i -g yarn
cd project/
yarn set version berry
Setup basic configuration .yarnrc.yml:
yarnPath: .yarn/releases/yarn-berry.cjs
nodeLinker: node-modules
npmPublishAccess: public
npmPublishRegistry: 'https://registry.npmjs.org'
npmRegistryServer: 'https://registry.npmjs.org'
Update .gitignore file:
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp/
.pnp.js
Yarn Configuration
yarn config set nodeLinker node-modules --home
yarn config set npmPublishAccess public --home
yarn config set npmRegistryServer "https://registry.npmjs.org" --home
yarn config set yarnPath .yarn/releases/yarn-berry.cjs --home
yarn config set unsafeHttpWhitelist --json '["localhost", "*.example.com", "example.com"]'
Yarn Updates
One line to update all deps in monorepo:
yarn up @types/node
yarn up @types/react
yarn dedupe --strategy highest
Yarn Workspace
yarn workspace packageName build
Yarn Plugin
yarn plugin list
Yarn Patch
Modify package in node_modules conveniently:
- Run
yarn patch <package>will create copy ofpackagetotmp/xfs-xxxxxxxx/user/. - After modify source code of
package, runyarn patch-commit /tmp/xfs-xxxxxxxx/user --save.
Yarn Berry Real World Case
- Gatsby:
yarn 1 with
.yarn/directory. - Redux ToolKit: yarn 2.
- Babel: yarn 3.
- StoryBook: yarn 3.