分步说明
你可能听说过 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
将你的配置更新为新设置
¥Update your configuration to the new settings
Modern 使 用与 Classic 不同的配置文件样式。虽然对于锁文件来说几乎是不可见的(因为我们会动态转换它们),但如果你依赖 .npmrc
或 .yarnrc
文件,它可能会导致问题。
¥Modern uses a different style of configuration files than Classic. While mostly invisible for the lockfile (because we convert them on the fly), it might cause issues if you rely on .npmrc
or .yarnrc
files.
-
Yarn Modern 现在使用
.yarnrc.yml
。现在忽略任何其他文件 - 这包括.npmrc
。¥Yarn Modern now uses
.yarnrc.yml
. Any other file is now ignored - this includes.npmrc
. -
从新的文件扩展名可以看出,Yarnrc 文件现在要用 YAML 编写。
¥As evidenced by the new file extension, the Yarnrc files are now to be written in YAML.
大多数配置键也已重命名以更加一致。可以在 .yarnrc.yml
专用文档 上找到可用设置的完整列表,但以下是一些重要的设置:
¥Most configuration keys have also been renamed to be more consistent. The comprehensive list of available settings can be found on the .yarnrc.yml
dedicated documentation, but here are some important ones:
-
现在通过
npmRegistryServer
配置自定义注册表。