# 简介
官网:https://yarnpkg.com/ (opens new window)
中文文档:https://yarn.bootcss.com/ (opens new window)
# 安装 yarn
npm install yarn -g # 安装yarn
yarn -v # 查看版本
npm update yarn -g # 更新yarn
1
2
3
2
3
# 新建工程
yarn init
yarn init -y
1
2
2
# 安装模块
yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]
yarn add [package] --dev # devDependencies 简写 yarn add [package] -D
yarn add [package] --peer # peerDependencies
yarn add [package] --optiona # optionalDependencies
yarn global add [package] # 全局安装
yarn install # 安装package.json中的包,如果node_modules中有的包刚不会重新下载
yarn install --force # 强制安装package.json中的包,node_modules中有的也会安装
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 卸载模块
yarn remove [package]
1
# 更新模块
yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]
yarn upgrade --latest # 忽略版本规则,升级到最新版本
1
2
3
4
2
3
4
# 查看包信息
yarn info [package]
yarn info [package] --json # 输出json格式
yarn info [package] readme # 输出README部分
1
2
3
2
3
# 查看安装信息
yarn list
yarn global list
yarn list --depth=0 # 限制依赖的深度
1
2
3
2
3
# 管理配置
yarn config
yarn config set key value # 设置
yarn config get key # 读取值
yarn config delete key # 删除
yarn config list # 显示当前配置
yarn config set registry https://registry.npmmirror.com # 设置淘宝镜像
1
2
3
4
5
6
2
3
4
5
6
# 缓存
yarn cache
yarn cache list # 列出已缓存的每个包
yarn cache dir # 返回全局缓存位置
yarn cache clean # 清除缓存
1
2
3
4
2
3
4