一、yarn 1.x

1. 全局安装

npm i yarn -g

手动设置淘宝源 yarn1.x npm

yarn config set registry https://registry.npmmirror.com

2. 配置文件

.npmrc

二、yarn2.x & yarn3.x

1. 使用corepack安装

node版本大于v16.13

1.1 开启corepack 功能

corepack enable

1.2开启高版本pnpm

corepack prepare yarn@3.1.1 --activate

2. yarn命令

2.1 查看配置

  • yarn config查看全部

    2.2 修改npm源

  • yarn config set npmRegistryServer https://registry.npmmirror.com 只能设置在本地,暂时不能全局设置

    3. 工程跑不起来的解决方案

    ```bash

    .yarnrc.yml

    npmRegistryServer: “https://registry.npmmirror.com

如果工程跑不起来可以先尝试增加下面的配置:

nodeLinker: “pnp” pnpMode: “loose”

如果仍然跑不起来,可以用下面的配置完全按照以前的依赖按照方式

nodeLinker: “node-modules”

  1. <a name="ZTG4z"></a>
  2. ### 4. .gitignore配置
  3. If you're using Zero-Installs:
  4. ```bash
  5. .yarn/*
  6. !.yarn/cache
  7. !.yarn/patches
  8. !.yarn/plugins
  9. !.yarn/releases
  10. !.yarn/sdks
  11. !.yarn/versions

If you’re not using Zero-Installs:

  1. .pnp.*
  2. .yarn/*
  3. !.yarn/patches
  4. !.yarn/plugins
  5. !.yarn/releases
  6. !.yarn/sdks
  7. !.yarn/versions

参考链接