
6

npm install报错&node-sass安装的正确姿势
source link: http://www.lzhpo.com/article/90
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

npm install报错&node-sass安装的正确姿势
什么是node-sass?
Node-sass是一个库,它将Node.js绑定到LibSass(流行样式表预处理器Sass的C版本)。它允许用户以令人难以置信的速度将.scss文件本地编译为css,并通过连接中间件自动编译。
什么是Sass?
Sass是一种预处理器脚本语言,可以解释或编译成层叠样式表(CSS)。
Sass包含两种语法:较旧的语法使用缩进将代码块和换行符分隔为单独的规则;较新的语法SCSS使用像CSS这样的块格式。它使用大括号来表示代码块和分号来分隔块中的行。
缩进语法和SCSS文件传统上分别给出扩展名.sass和.scss
报错原因分析
node-sass无法正常安装。
安装node-sass的正确姿势
法1【推荐】
设置全局镜像源:
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
之后再涉及到 node-sass 的安装时就会从淘宝镜像下载。
npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/// 也可以设置系统环境变量的方式。示例// linux、mac 下SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass// window 下set SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ && npm install node-sass
使用 cnpm 安装 node-sass 会默认从淘宝镜像源下载,也是一个办法:
cnpm install node-sass
在项目根目录创建.npmrc文件,复制下面代码到该文件。
phantomjs_cdnurl=http://cnpmjs.org/downloadssass_binary_site=https://npm.taobao.org/mirrors/node-sass/registry=https://registry.npm.taobao.org
保存后 删除之前安装失败的包(第一次安装请跳过此步)
npm uninstall node-sass
npm install node-sass
- 本文作者: lzhpo
- 本文链接: http://www.lzhpo.com/article/90
- 版权声明: 本文为本人原创文章,采用 CC BY 3.0 CN协议 ,可自由转载、引用,但需署名作者且注明文章出处。
正文到此结束
所属分类:前端技术
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK