NPM和Yarn命令对比

npm 命令 Yarn 命令 备注
npm install yarn install 安装依赖包
(N/A) yarn install —flat 单版本模式
(N/A) yarn install —har 生成har文件,记录安装时网络请求性能
(N/A) yarn install —no-lockfile 不读写lockfile方式
(N/A) yarn install —pure-lockfile 不生成yarn.lock文件
npm install [package] (N/A) 安装依赖
npm install —save [package] yarn add [package] 添加生产模式依赖到项目
npm install —save-dev [package] yarn add [package] [—dev/-D] 添加开发模式的依赖
(N/A) yarn add [package] [—peer/-P] 对等模式添加依赖,发布/分享项目时的依赖
npm install —save-optional [package] yarn add [package] [—optional/-O]
npm install —save-exact [package] yarn add [package] [—exact/-E]
(N/A) yarn add [package] [—tilde/-T]
npm install —global [package] yarn global add [package]
npm rebuild yarn install —force
npm uninstall [package] (N/A)
npm uninstall —save [package] yarn remove [package]
npm uninstall —save-dev [package] yarn remove [package]
npm uninstall —save-optional [package] yarn remove [package]
npm cache clean yarn cache clean
rm -rf node_modules && npm install yarn upgrade -