跳到主要内容
版本号:6.x

yarn

Yarn (1.x)

注意npm配置在经典版本上是有效的

经典版本能够读取 .npmrc 文件,但也提供它们自己的配置文件 .yarnrc

要设置一个注册中心(registry),创建一个文件并定义它。

// .yarnrc
registry "http://localhost:4873"

使用这个版本时,你应该在你使用的配置中启用 always-auth

npm config set always-auth true

yarn@1.xyarn install 上不发送授权头,如果你的软件包需要认证,通过启用 always-auth 将强制 yarn 在每个请求上发送。

Yarn Berry (>=2.x)

Yarn berry 不再读取 --registry 配置或者 .npmrc 文件。

要定义注册中心(registry),你必须使用项目根目录下的 .yarnrc.yml 或者全局配置。

当你发布软件包时,npmRegistryServer 必须配置。 请记住,package.json 中的 publishConfig.registry 将覆盖这个配置。

// .yarnrc.yml
npmRegistryServer: "http://localhost:4873"

unsafeHttpWhitelist:
- localhost

unsafeHttpWhitelist 仅在你不使用具有有效证书的 https 时才需要配置。

使用作用域(scope) 也是可以的,并且更加细分,如果需要的话,你可以为作用域定义 token 配置。

npmRegistries:
"https://registry.myverdaccio.org":
npmAlwaysAuth: true
npmAuthToken: <TOKEN>
npmScopes:
my-company:
npmRegistryServer: https://registry.myverdaccio.org
npmPublishRegistry: https://registry.myverdaccio.org

要从 CLi 登录,使用:

yarn npm login --scope my-company