yarn概述
mac下安装yarn: brew update && brew install yarn 或者如果已经存在NPM的情况下,执行npm i yarn -g 即可
添加依赖:yarn add package@version -dev
升级依赖:yarn upgrade package@version
移除依赖: yarn remove package
根据packages.json 安装所有依赖,执行yarn或者yarn install
为什么要从NPM到Yarn?
- Yarn允许使用某个lockfile来保证团队中的所有人使用相同版本的npm依赖包,这一点会大大减少因为某个人系统本身问题而导致的Bug。
-Yarn允许离线安装某些依赖
-Yarn采用了新的算法来保证速度
实用命令
- yarn why:这条命令能帮助开发者理清安装的 package 之间的关系。
- yarn licenses generate-disclaimer 将生成一个对所有依赖的免责声明。
等价的命令
npm install === yarn
npm install taco --save === yarn add taco
npm uninstall taco --save === yarn remove taco
npm install taco --save-dev === yarn add taco --dev
npm update --save === yarn upgrade
npm install taco@latest --save === yarn add taco
npm install taco --global === yarn global add taco
完全相同的命令
npm init === yarn init
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 (and logout)
npm test === yarn test
npm install --production === yarn --production
参考:
https://shift.infinite.red/npm-vs-yarn-cheat-sheet-8755b092e5cc
http://www.zcfy.cc/article/yarn-vs-npm-everything-you-need-to-know-1484.html
网友评论