一、初始化
yarn init
// 对比
npm init
二、安装
yarn add
yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]
yarn add [package] // 将依赖项添加 dependencies
yarn add [package] --dev //将依赖项添加 devDependencies
// 对比
npm install 或 npm i
npm install [package]
npm install [package]@[tag]
npm install [package]@[version]
npm install [package] --save // 将依赖项添加 dependencies
npm install [package] --save-dev //将依赖项添加 devDependencies
三、删除
yarn remove [package]
// 对比
npm uninstall [package]
四、升级
yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]
yarn global upgrade
// 对比
rm -rf node_modules && npm install [package]
npm update --global
五、清除缓存
yarn cache clean [package]
// 对比
npm cache clean
六、重构依赖
yarn add --force
// 对比
npm rebuild
七、其它
yarn add --no-lockfile
yarn add [package] --optional
yarn add [package] --exact
// 对比
npm install --no-package-lock
npm install [package] --save-optional
npm install [package] --save-exact