秘诀
TypeScript + PnP 快速入门:
¥TypeScript + PnP quick start:
-
使用 Yarn 2 初始化 repo:
¥Initialize the repo using Yarn 2:
-
添加 typescript 并启用 VSCode 集成:
¥Add typescript and enable VSCode integration:
在指定目录中运行 Yarn CLI 命令:
¥Running a Yarn CLI command in the specified directory:
-
直接在 monorepo 中启动新库,而无需为其手动创建目录。
¥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 --noEmit
混合 PnP + node_modules mono-repo:
¥Hybrid PnP + node_modules mono-repo:
有时,你可能只需要在工作区的一部分上使用 node_modules
(例如,如果你使用 React-Native)。
¥You may sometimes need to use node_modules
on just part of your workspace (for example, if you use React-Native).
-
为
node_modules
项目创建一个单独的目录。¥Create a separate directory for the
node_modules
project.
mkdir nm-packages/myproj
touch nm-packages/myproj/yarn.lock
-
启用
node-modules
链接器:¥Enable the
node-modules
linker :
-
在你的 monorepo 根目录的主
.yarnrc.yml
中为此路径添加 PnP 忽略模式:¥Add a PnP ignore pattern for this path in your main
.yarnrc.yml
at the root of your monorepo:
pnpIgnorePatterns:
- ./nm-packages/**
-
运行
yarn install
以在 repo 根目录中应用pnpIgnorePatterns
。¥Run
yarn install
to applypnpIgnorePatterns
in the repo root. -
运行
cd nm-packages/myproj && yarn
以安装现在隔离的项目。¥Run
cd nm-packages/myproj && yarn
to install the now isolated project.