1. npm
# 升级npm
sudo npm install npm -g #linux
# 清除所有npm缓存
npm cache clean --force
# 查看所有config
npm config list
# 配置国内镜像源
# npm config set registry https://registry.npm.taobao.org (旧作废)
npm config set registry https://registry.npmmirror.com
# 查看当前镜像源
npm config get registry
# 恢复原来镜像源
npm config set registry http://registry.npmjs.org
2. cnpm
# 安装
npm install -g cnpm --registry=https://registry.npm.taobao.org
3. yarn
# 安装
cnpm i yarn -g --verbose
# 原yarn镜像源
https://registry.yarnpkg.com
# 查看所有config
yarn config list
# 配置淘宝镜像
# yarn config set registry https://registry.npm.taobao.org/ -g (旧作废)
yarn config set registry https://registry.npmmirror.com
4. npm与yarn使用命令的区别
|
npm |
yarn |
安装依赖 |
npm install<br />简写:npm i |
yarn install<br />简写:yarn i |
安装生产环境包 |
npm install [package] --save<br />简写:npm i [package] |
yarn add [package] |
安装开发环境包 |
npm install [package] --save-dev<br />简写:npm i [package] -S |
yarn add [package] --dev |
安装全局环境包 |
npm install [package] --global<br />简写:npm i [package] -g |
yarn add [package] global |
卸载生产环境包 |
npm uninstall [package] --save<br />简写:npm uninstall [package] |
yarn remove [package] |
卸载开发环境包 |
npm uninstall [package] --save-dev<br />简写:npm uninstall [package] -S |
yarn remove [package] |
更新某个依赖 |
npm rebuild [package] |
yarn add [package] --force |
网友评论