介绍
这是一个备忘单,您可以将其用作npm和Yarn命令的方便参考。
有关 npm 的更全面概述,请浏览我们的教程How To Use Node.js Modules with npm 和 package.json
。
npm 与 Yarn
npm和Yarn之间有很多相似之处。Yarn(2016 年发布)从npm(2010年)中汲取了大量灵感。
另一方面,当您发现自己同时使用这两个包管理器时,它们的相似性可能会导致混淆和小错误。
以下是保持两个 CLI 直截了当的有用参考:
| 命令 | 新产品经理 | 纱 |
|---|---|---|
| 安装依赖 | npm install |
yarn |
| 安装包 | npm install [package] |
yarn add [package] |
| 安装开发包 | npm install --save-dev [package] |
yarn add --dev [package] |
| 卸载包 | npm uninstall [package] |
yarn remove [package] |
| 卸载开发包 | npm uninstall --save-dev [package] |
yarn remove [package] |
| 更新 | npm update |
yarn upgrade |
| 更新包 | npm update [package] |
yarn upgrade [package] |
| 全局安装包 | npm install --global [package] |
yarn global add [package] |
| 全局卸载包 | npm uninstall --global [package] |
yarn global remove [package] |
没有改变的事情
以下是Yarn决定不更改的一些命令:
| 新产品经理 | 纱 |
|---|---|
npm init |
yarn init |
npm run |
yarn run |
npm test |
yarn test |
npm login(和logout) |
yarn login(和logout) |
npm link |
yarn link |
npm publish |
yarn publish |
npm cache clean |
yarn cache clean |
结论
有关 npm 的更全面概述,请浏览我们的教程How To Use Node.js Modules with npm 和 package.json
。