npm 是一个包管理器。Node.js 自带。npm
cnpm 是 npm 的阿里版,用的阿里源。segmentfault
yarn 是另外一个包管理器,不自带,须要另外装。能够单独装,也能够用 npm 装。spa
tyarn 是 yarn 的阿里版,用的阿里源。代理
安装 cnpmcode
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
npm 怎么用,cnpm就怎么用。blog
安装 tyarnget
npm i yarn tyarn -g
yarn 怎么用,tyarn就怎么用。class
npm 换淘宝源。cnpm
npm config set registry https://registry.npm.taobao.org
换回来。淘宝
npm config set registry https://registry.npmjs.org
看一下如今是什么源。
npm config get registry
yarn 同理。
yarn config set registry https://registry.npmjs.org
yarn config set registry https://registry.npm.taobao.org
yarn config get registry
npm 设置代理
npm config set proxy=http://127.0.0.1:8087
npm config set https-proxy=http://127.0.0.1:8087
npm 取消代理
npm config delete proxy
npm config delete https-proxy
yarn 设置代理
yarn config set proxy http://XXX
yarn config set https-proxy http://XXX
yarn 取消代理
yarn config delete proxy
yarn config delete https-proxy
还有一个指定目录换源的方法。
新建一个.npmrc 到须要 yarn 的目录
registry=https://registry.npm.taobao.org
内容如上。
对于个别很难下载的库,还能够经过设置 SASS_BINARY_SITE 解决。
参考:http://www.javashuo.com/article/p-txekbilh-hn.html
综上所述,装依赖遇到困难时,至少有4种方法。
SASS_BINARY_SITE
以上。