本文整理了 NPM 和 Node.js 开发中的常用配置技巧。
NPM 镜像配置
国内使用 NPM 下载包较慢,可以切换到国内镜像加速:
临时使用
1
| npm install <package> --registry=https://registry.npmmirror.com
|
永久配置
1 2 3 4 5 6 7 8 9 10 11
| npm config set registry https://registry.npmmirror.com
npm config set registry http://registry.cnpmjs.org
npm config get registry
npm config set registry https://registry.npmjs.org
|
使用 nrm 管理多个源
1 2 3 4 5 6 7 8 9 10 11
| npm install -g nrm
nrm ls
nrm use taobao
nrm test
|
参考: 重置npm镜像代理,提高node包下载速度
常用 NPM 命令
| 命令 |
说明 |
npm init |
初始化项目 |
npm install |
安装所有依赖 |
npm install <pkg> --save |
安装并添加到 dependencies |
npm install <pkg> --save-dev |
安装并添加到 devDependencies |
npm update |
更新依赖 |
npm outdated |
查看过期依赖 |
npm cache clean --force |
清理缓存 |