1️⃣ yarn

2️⃣ 初始化

初始化:**yarn init [--yes/-y]**

2️⃣ 安装

添加指定包:**yarn [global] add package-name [--dev/-D] [--exact/-E]**
安装package.json中的所有依赖:**yarn install [--production/--prod]**

2️⃣ 脚本和本地CLI

运行脚本:**yarn run 脚本名**

start、stop、test可以省略run

运行本地安装的CLI:**yarn run CLI名**

2️⃣ 查询

查看bin目录:**yarn [global] bin**
查询包信息:**yarn info 包名 [子字段]**
列举已安装的依赖:**yarn [global] list [--depth=依赖深度]**

yarn的list命令和npm的list不同,yarn输出的信息更加丰富,包括顶级目录结构、每个包的依赖版本号

2️⃣ 更新

列举需要更新的包:**yarn outdated**
更新包:**yarn [global] upgrade [包名]**

2️⃣ 卸载

卸载包:**yarn remove 包名**

1️⃣ yarn 命令与npm命令的对应关系如下:

2️⃣ 初始化项目

  1. yarn init -y
  2. npm init -y

2️⃣ 下载项目的所有声明的依赖

  1. yarn
  2. npm install

2️⃣ 下载指定的运行时依赖包

  1. yarn add xxxx@3.2.1
  2. npm install xxxxx@3.2.1 -S

2️⃣ 下载指定的开发时依赖

  1. yarn add xxxxx@3.2.1 -D
  2. npm install xxxxx@3.2.1 -D

2️⃣ 全局下载指定包

  1. yarn global add xxxxxx
  2. npm install xxxxxxx -g

2️⃣ 删除依赖包

  1. yarn remove xxxxx
  2. yarn global remove xxxxxx
  3. npm remove xxxxxxx -g

2️⃣ 查看某个包的信息

  1. yarn info xxx
  2. npm info xxx

2️⃣ 设置淘宝镜像

  1. yarn config set registry https://registry.npm.taobao.org
  2. npm config set registry https://registry.npm.taobao.org