day10 yarn 使用详细介绍

61 阅读1分钟

Yarn 常用命令

  • npm install === yarn // install安装是默认行为

  • npm install lodash --save === yarn add lodash // lodash 包立即被保存到 package.json 中。

  • npm uninstall lodash --save === yarn remove lodash

  • npm install lodash --save-dev === yarn add lodash --dev

  • npm update --save === yarn upgrade

  • npm install lodash@latest --save === yarn add lodash

  • npm install lodash --global === yarn global add lodash // 一如既往,请谨慎使用 global 标记。

注意:使用yarn或yarn install安装全部依赖时是根据package.json里的”dependencies”字段来决定的

  • npm init === yarn init
  • npm init --yes/-y === yarn init --yes/-y
  • npm link === yarn link
  • npm outdated === yarn outdated
  • npm publish === yarn publish
  • npm run === yarn run
  • npm cache clean === yarn cache clean
  • npm login === yarn login
  • npm test === yarn test

Yarn 独有的命令

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

Yarn 换源

Yarn 源仓库包下载不稳定

// 查看 yarn 配置
yarn config get registry
或者
yarn config list

> registry: 'https://registry.yarnpkg.com' 
// 安装淘宝镜像
yarn config set registry https://registry.npm.taobao.org