Skip to main content

安装

  1. 安装 Corepack,这是一个中间工具,可让你根据项目配置包管理器版本:

    ¥Install Corepack, an intermediary tool that will let you configure your package manager version on a per-project basis:

npm install -g corepack
  1. 然后初始化一个新项目:

    ¥Then initialize a new project:

yarn init -2

更新 Yarn

¥Updating Yarn

任何时候你想要将 Yarn 更新到最新版本,只需运行:

¥Any time you'll want to update Yarn to the latest version, just run:

yarn set version stable
yarn install

然后,Yarn 将配置你的项目以使用最新的稳定二进制文件。

¥Yarn will then configure your project to use the most recent stable binary.

提示

Yarn 也经常发布候选版本。如果你需要尚未在稳定通道上发布的功能,请使用 yarn set version canary。这些版本非常稳定,与常规渠道的唯一区别是,随着我们实现新的重大变化,主要版本之间的迁移更加交错。

¥Yarn also frequently ships Release Candidate builds. Use yarn set version canary should you need a feature not released on the stable channel yet. Those builds are very stable, the only difference with the regular channel being a more staggered migration between major as we implement new breaking changes.

从 master 安装最新版本

¥Installing the latest build fresh from master

你可能想要测试一个最近的 Yarn 版本,它尚未在候选版本中发布,甚至尚未合并。以下命令将直接从我们的存储库克隆、构建和安装 Yarn 到你的项目中:

¥You may want to test a version of Yarn so recent it hasn't been released in a Release Candidate yet, or even not merged. The following command will clone, build, and install Yarn in your project, straight from our repository:

它接受 --branch 标志,你可以使用它来测试特定的 PR:

¥It accepts a --branch flag which you can use to test specific PRs:

yarn set version from sources --branch 1211
警告

与稳定和预览渠道不同,yarn set version from sources 命令无法利用 Corepack,需要将 Yarn 二进制文件存储在 .yarn/releases 文件夹中,并从项目的 .yarnrc.yml 文件中引用它。

¥Unlike the stable and canary channels, the yarn set version from sources command can't leverage Corepack and will need to store the Yarn binary inside the .yarn/releases folder and reference it from your project's .yarnrc.yml file.