初始化一个新的项目
yarn init --yes # 简写 -y
npm init --yes # 简写 -y
yarn add <package...> [--dev/-D] //不带-D默认生产环境
yarn add [package]@[version] #带版本
npm install XXX --save 可以简写成npm i XXX -S --------> 安装项目依赖
npm install XXX --save-dev可以简写成npm i XXX -D ------> 安装开发依赖
yarn global add [package]
npm install [package] -g
yarn upgrade # 升级所有依赖项,不记录在 package.json 中
npm update # npm 可以通过 ‘--save|--save-dev’ 指定升级哪类依赖
yarn upgrade webpack # 升级指定包
npm update webpack --save-dev # npm
yarn upgrade --latest # 忽略版本规则,升级到最新版本,并且更新 package.json
yarn remove <packageName>
npm uninstall <packageName> -S
yarn global list --depth=0 # 限制依赖的深度
npm list -g --depth=0
npm config get registry // 查看npm当前镜像源
npm config set registry https://registry.npm.taobao.org/ // 设置npm镜像源为淘宝镜像
yarn config get registry // 查看yarn当前镜像源
yarn config set registry https://registry.npm.taobao.org/ // 设置yarn镜像源为淘宝镜像
镜像源地址部分如下:
npm --- https://registry.npmjs.org/
cnpm --- https://r.cnpmjs.org/
taobao --- https://registry.npm.taobao.org/
yarn cache clean
npm cache clean --force
yarn info <package...>
npm v <package...> versions //缩写
参考:https://www.cnblogs.com/cjh1996/p/12688383.html