Recipes
Edit this page on GitHubTypeScript + PnP quick start:
- Initialize the repo using Yarn 2:
yarn init -2- Add typescript and enable VSCode integration:
yarn add --dev typescript
yarn dlx @yarnpkg/sdks vscode- You can optionally enable Yarn's TypeScript plugin, which helps manage
@types/*dependencies automatically.
yarn plugin import typescriptRunning a Yarn CLI command in the specified directory:
- Starting a new library inside a monorepo directly, without manually creating directories for it.
yarn packages/my-new-lib init- Running an arbitrary command inside a specific workspace:
yarn packages/app tsc --noEmitHybrid PnP + node_modules mono-repo:
You may sometimes need to use node_modules on just part of your workspace (for example, if you use React-Native).
- Create a separate directory for the
node_modulesproject.
mkdir nm-packages/myproj- Create an empty lockfile in the new project. Yarn uses lockfiles to locate the root of projects.
touch nm-packages/myproj/yarn.lock- Add a
.yarnrc.ymlfile inside the new directory that enablesnode_modulesjust for it (nm-packages/myproj/.yarnrc.yml):
nodeLinker: node-modules- Add a PnP ignore pattern for this path in your main
.yarnrc.ymlat the root of your monorepo:
pnpIgnorePatterns:
- ./nm-packages/**- Run
yarnto applypnpIgnorePatternsin the repo root. - Run
cd nm-packages/myproj && yarnto install the now isolated project.