yarn和npm操作对比

初始化一个新的项目

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 run

npm run

移除一个依赖

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
posted @ 2020-12-16 15:05  zph前端  阅读(130)  评论(0编辑  收藏  举报