配置淘宝镜像源的正确姿势 安装node-sass的正确姿势

4,597 阅读1分钟

windows下面安装node-sass,确实令人头痛,正确姿势如下:

1、npm或yarm指定淘宝镜像

查看镜像

# npm命令
npm config get registry
# yarn命令
yarn config get registry

修改为淘宝镜像

# npm命令
npm config set registry http://registry.npm.taobao.org/
# yarn命令
yarn config set registry http://registry.npm.taobao.org/

此时,正常情况再安装node-sass都可以成功,如果安装还报错,则进入下面第二步。安装编译windows平台编译环境

2、安装windows平台编译环境(需要在管理员权限下安装)

npm install -g node-gyp
npm install --global --production windows-build-tools 

3、当然也可在项目目录下临时安装指定node-sass为镜像淘宝

npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/

以上三步,基本保证node-sass安装成功!

小tips npm config get registry npm config set registry registry.npm.taobao.org/ npm i

nrm ls

  npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/
  nj --------- https://registry.nodejitsu.com/
  npmMirror -- https://skimdb.npmjs.com/registry/
  edunpm ----- http://registry.enpmjs.org/

nrm use taobao