npm
- 查看源:
npm config get registry
- 永久切换源、设置源
npm config set registry https://xxxxxxxx
- 临时使用源
npm i xx --registry https://xxxxxxx
- 查看全局安装的包
npm list -g --depth 0
- 安装指定版本/最新版本
npm i <module name>@1.0.0 //安装指定版本的模块
npm i <module name>@latest //最新
- 安装位置:
npm root -g //查看全局node_modules路径
npm root //查看本地node_modules路径
- 清理缓存后重新安装(适用:依赖缺失重新安装)
npm cache clean --force
npm install xxx
- 当某个依赖安装失败,可忽略后单独安装
npm install xxx@0.1.21 --ignore-scripts
npm i xxx@0.1.21
一些后缀:
-S, --save 安装包信息将加入到dependencies(生产阶段的依赖)
-D, --save-dev 安装包信息将加入到devDependencies(开发阶段的依赖),所以开发阶段一般使用它
-O, --save-optional 安装包信息将加入到optionalDependencies(可选阶段的依赖)
-E, --save-exact 精确安装指定模块版本
-P, --save-prod, 添加dependencies 里面所有的包
官方源:
https://registry.npmjs.org/
淘宝源:
https://registry.npm.taobao.org
nrm的使用
安装nrm:sudo npm install -g nrm
查看是否安装成功:nrm --version
查看源列表:nrm ls
~ nrm ls
npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
rednpm - http://registry.mirror.cqupt.edu.cn/
npmMirror https://skimdb.npmjs.com/registry/
edunpm - http://registry.enpmjs.org/
使用源 nrm use xxx
添加源nrm add registryname url
删除源:nrm del registryname