Skip to main content

yarn

安装

npm i yarn -g

常用命令

  • 查看当前使用的源
yarn config get registry
  • 更新包

    # 如果模块有多个版本,则会列出
    yarn upgrade xxxx@x.x.x
  • 安装包

    # 安装
    yarn global add {name}
    yarn add {name} --dev
    yarn add {name} --registry https://registry.npm.taobao.org --no-bin-links

    # 卸载
    yarn remove {name}
  • 卸载包

    yarn remove name
  • 初始化项目

    yarn
    yarn -y
    yarn create xxxx <dir-name>
  • 源设置

    # 列出配置
    yarn config list

    # 查看当前源
    yarn config get registry

    # 设置镜像源
    yarn config set registry https://registry.npm.taobao.org/
    yarn config set registry https://mirrors.huaweicloud.com/repository/npm/

独有命令

yarn licenses ls —— 允许你检查依赖的许可信息
yarn licenses generate —— 自动创建依赖免责声明 license
yarn why taco —— 检查为什么会安装 taco,详细列出依赖它的其他包
yarn why vuepress —— 检查为什么会安装 vuepress,详细列出依赖它的其他包

设置缓存

# 查看当前缓存路径
yarn cache dir

# 全局bin位置
yarn global bin

# 修改缓存路径
yarn config set cache-folder "c:/cache/yarn"
yarn config set cache-folder "d:/tcache/yarn"


# 清除缓存
yarn cache clean

配置文件

  • 注意格式中 value 需要用双引号包裹,否则某些情况下可能会报错
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


registry "https://registry.npm.taobao.org/"
ELECTRON_BUILDER_BINARIES_MIRROR "http://npm.taobao.org/mirrors/electron-builder-binaries/"
ELECTRON_MIRROR "https://cdn.npm.taobao.org/dist/electron/"
lastUpdateCheck 1648776789761