npm默认镜像源是国外的,安装依赖速度较慢,使用国内的镜像源速度会快一些。
1、设置淘宝镜像源:
#最新地址 淘宝 NPM 镜像站喊你切换新域名啦!
npm config set registry (弃用了)
npm config set registry (新的)
2、查看当前镜像源:
npm config get registry
3、设置官方镜像源:
npm config set registry
还可以使用nrm查看和切换镜像
//安装nrm,一定要全局安装
npm install -g nrm
//nrm查看所有镜像源命令,带*即为当前使用的源
nrm ls
npm ---------- /
yarn --------- /
tencent ------ /npm/
cnpm --------- /
* taobao ------- /
npmMirror ---- /registry/
//如果使用nrm ls发现全面都没有带*,则可以参考最后面的教程
//切换镜像源命令
nrm use xxx //例:nrm use taobao 就可以切换自己想用的镜像源了
//当前使用的源
nrm current
taobao
二、使用cnpm安装
npm install -g cnpm --registry=
# 注册模块镜像
npm set registry
// node-gyp 编译依赖的 node 源码镜像
npm set disturl /dist
// 清空缓存
npm cache clean --force
// 安装cnpm
npm install -g cnpm --registry=
三、常见包地址
# mirror config
sharp_binary_host = /mirrors/sharp
sharp_libvips_binary_host = /mirrors/sharp-libvips
profiler_binary_host_mirror = /mirrors/node-inspector/
fse_binary_host_mirror = /mirrors/fsevents
node_sqlite3_binary_host_mirror = /mirrors
sqlite3_binary_host_mirror = /mirrors
sqlite3_binary_site = /mirrors/sqlite3
sass_binary_site = /mirrors/node-sass
electron_mirror = /mirrors/electron/
puppeteer_download_host = /mirrors
chromedriver_cdnurl = /mirrors/chromedriver
operadriver_cdnurl = /mirrors/operadriver
phantomjs_cdnurl = /mirrors/phantomjs
python_mirror = /mirrors/python
registry =
disturl = /dist