npm 与 yarn 对比
npm | yarn |
---|---|
npm init | yarn init |
npm install | yarn install |
(N/A) | yarn install --flat |
(N/A) | yarn install --har |
(N/A) | yarn install --no-lockfile |
(N/A) | yarn install --pure-lockfile |
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 |
yarn 的安装:
1.推荐
brew install yarn
2.不推荐
npm install -g yarn
初始化项目
npm:
npm init
yarn:
yarn init
从 package.json 安装依赖
npm:
npm install
yarn:
yarn
安装指定包到依赖或者开发依赖
npm:
npm install --save [package]
npm install --save-dev [package]
yarn:
yarn add [package]
yarn add [package] [--dev/-D]
安装包到全局
npm:
npm install --global [package]
yarn:
yarn global add [package]
安装指定版本的包
npm:
npm install [package]@[version]
yarn:
yarn add [package]@[version]
重新下载所有包
npm:
npm rebuild
yarn:
yarn install --force
卸载包
npm:
npm uninstall [package]
npm uninstall --save [package]
npm uninstall --save-dev [package]
yarn:
yarn remove [package]
升级包
npm:
rm -rf node_modules && npm install
yarn:
yarn upgrade