使用 CNPM 推荐
1 | npm i cnpm -g |
淘宝 NPM 镜像
npm install 默认registry是https://registry.npmjs.org/
,下载比较慢,修改为淘宝镜像可以解决这个问题
1 | npm config set registry https://registry.npm.taobao.org/ |
设置loglevel=http
可以查看下载进度
1 | npm config set loglevel http |
npm配置文件.npmrc
在 C:\Users\zhanqi\.npmrc
淘宝开源镜像
配置了Npm镜像后,安装部分依赖还是会遇到慢的问题。
在npm install node-sass
的时候,控制台会看到正在从github下载一个darwin-x64-11_binding.node
的文件,这是一个二进制文件,并不存在npm仓库,而是直接从github下载,下载非常慢,解决办法有两种:
1. 浏览器手动下载
- https://github.com/sass/node-sass/releases/download/v4.5.2/darwin-x64-11_binding.node
- 保存到
npm-cache
目录:C:\Users\zhanqi\AppData\Roaming\npm-cache\node-sass\4.5.2
- 下载完成,再次安装
npm install node-sass
2. 使用淘宝开源镜像
淘宝开源镜像 https://npm.taobao.org/mirrors/ 主要提供github上的部分开源项目releases downloads
链接,比如node-sass:https://npm.taobao.org/mirrors/node-sass/v4.5.2/darwin-x64-11_binding.node
配置镜像地址
我们已经配置了淘宝npm镜像,为什么还会去github下载呢?
找到node-sass的源码 https://github.com/sass/node-sass/blob/master/lib/extensions.js 有一个getBinaryUrl
函数:
1 | function getBinaryUrl() { |
node-sass提供了四种配置方法
1. npm install arguments
1 | npm install node-sass --sass-binary-site=https://npm.taobao.org/mirrors/node-sass |
2. node env
添加SASS_BINARY_SITE
到 PATH
1 | set process.env.SASS_BINARY_SITE = https://npm.taobao.org/mirrors/node-sass |
3. npm config
1 | npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass |
4. package.json 推荐
不依赖本机,不用每个人都配置
1 | "nodeSassConfig": { |
附:其它常用 Mirrors 配置
1 | npm install phantomjs --phantomjs_cdnurl=http://npm.taobao.org/mirrors/phantomjs |
1. phantomjs
https://github.com/Medium/phantomjs/blob/master/lib/util.js getDownloadSpec
函数
2. chromedriver
https://www.npmjs.com/package/chromedriver