分步说明
你可能听说过 Yarn Plug'n'Play,并担心你的项目尚不兼容。别担心!
¥You may have heard about Yarn Plug'n'Play and be worried that your project isn't compatible yet. Don't worry!
此迁移将允许你保留 node_modules
文件夹。只有在我们完成后,你才必须决定是否要花时间迁移到 Yarn PnP。无论你这样做还是留在 node_modules
上,迁移到 Yarn Modern 都会有 许多好处。
¥This migration will let you keep your node_modules
folder. It's only once we're done that you'll have to decide whether you want to spend time migrating to Yarn PnP. Whether you do it or stay on node_modules
, migrating to Yarn Modern will have many benefits.
迁移步骤
¥Migration steps
-
确保你使用的是 Node 18+
¥Make sure you're using Node 18+
-
运行
corepack enable
以激活 Corepack¥Run
corepack enable
to activate Corepack -
进入你的项目目录
¥Go into your project directory
-
运行
yarn set version berry
¥Run
yarn set version berry
-
将你的
.npmrc
和.yarnrc
文件转换为.yarnrc.yml
(详情见 此处)¥Convert your
.npmrc
and.yarnrc
files into.yarnrc.yml
(details here) -
运行
yarn install
来迁移锁定文件¥Run
yarn install
to migrate the lockfile -
提交所有更改
¥Commit all changes
很好,你现在应该有一个可以正常工作的 Yarn 安装!有些事情可能仍需要对 CI 脚本进行一些调整(例如弃用 任意 pre/post
脚本,或将 --frozen-lockfile
重命名为 --immutable
),但至少我们有一个可运行的项目。
¥Good, you should now have a working Yarn install! Some things might still require some adjustments in your CI scripts (for example the deprecation of arbitrary pre/post
-scripts, or the renaming of --frozen-lockfile
into --immutable
), but at least we have a working project.
重大变化
¥Breaking changes