npm && yarn常用命令

Published on
发布于·预估阅读3分钟
Authors
  • Name
    willson-wang
    Twitter

创建package.json

npmyarn
npm init or npm init -yyarn init or yarn init -y

安装模块

npmyarn
npm install lodash or npm i lodash or npm i lodash --saveyarn add lodash
npm install webpack --save-devyarn add webpack --dev
npm install webpack -Dyarn add webpack -D
npm i [email protected]yarn add [email protected]
npm i react react-dom prop-types --saveyarn add react react-dom prop-types
npm i @babel/{core,cli} --save-devyarn add @babel/{core,cli} --dev
npm i npm-checked -gyarn global add npm-checked

卸载模块

npmyarn
npm uninstall webpackyarn remove webpack
npm uninstall react react-dom prop-typesyarn remove react react-dom prop-types
npm uninstall @babel/{core,cli}yarn remove @babel/{core,cli}

获取安装包信息

npmyarn
npm view reactyarn info react
npm view react versionyarn info react version
npm view react versionsyarn info react versions
npm view react readmeyarn info react readme

搜索安装包

npmyarn

依赖枚举

npmyarn
npm list or npm lsyarn ls
npm list --depth=0yarn list --depth=0
yarn list --depth=0 --pattern=md5
yarn list --depth=0 --pattern="md5
npm ls -g --depth=0

查看最新依赖

npmyarn
npm outdateyarn outdated
npm outdate qsyarn outdated qs

更新依赖

npmyarn
npm outdateyarn outdated
npm updateyarn upgrade
npm update qsyarn upgrade [email protected]

注意yarn upgrade不会更新package.json内依赖的版本号,解决方法可参考issues

本地软链接

npmyarn
npm link && cd app && npm link xxxyarn link && cd app && yarn link xxx
yarn unlink && cd app && yarn unlink xxx