Comparison and difference between npm and yarn commands

npm OR yarn

  • Guide to create a package.json file in the project
npm init

yarn init
  • Install all dependent packages (according to the dependency configuration parameters in package.json)
npm install

yarn install/yarn
  • Global installation dependencies
npm install -g <package>

yarn global add <package>
  • Install and add the installation package information to the dependencies (dependencies in the production phase)
npm install --save <package>

或者 npm install -S <package>

yarn add <package>
  • Install and add the installation package information to devDependencies (dependency in the development phase), which is generally used in the development phase
npm install --save-dev <package>

或者 npm install -D <package>

yarn add --dev <package>
  • Delete official dependencies
npm uninstall --save <package>

yarn remove <package>
  • Delete development dependencies
npm uninstall --save-dev <package>

yarn remove <package>
  • Remove global dependencies
npm uninstall -g <package>
yarn global remove <package>
  • Update development dependencies
npm update <package>

yarn upgrade <package>
  • Update global dependencies
npm update -g <package>

yarn global upgrade <package>
  • clear cache
npm cache clean

yarn cache clean

Guess you like

Origin blog.csdn.net/weixin_43956521/article/details/111469194