记录一下安装node-sass的过程.关于CSS是否是一门编程语言,这里不讨论,可是它没有变量 语句 函数(反正我以为他不是编程语言).因而程序员们发明了CSS预处理器(css preprocessor),它是一种专门的编程语言,可使用你会的基本的编程知识进行编程,而后再转化成css文件.
主流的CSS预处理器有8种,咱们今天介绍sass
.它的官网,不过须要安装ruby.javascript
node-sass
吧.github主页 deepin Linux 15.5
版本因为node-sass会去github主页下载binding-node,而后又去亚马逊去下载,因此国内由于一些不可抗力没法下载.简单的进行以下的设置,都是初学者,我就不用命令的形式写了,下面直接写上内容.基本的命令用多了也就会了.css
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/ electron_mirror=https://npm.taobao.org/mirrors/electron/ registry=https://registry.npm.taobao.org/ //顺序好像会有影响,我一开始不是这个顺序,后来改为这个,能安装成功
export SASS_BINARY_SITE="https://npm.taobao.org/mirrors/node-sass"
npm i -g node-sass
sudo npm i -g node-sass
npm rebulid node-sass
然而成功是属于其余人的.html
sudo
.Troubleshooting
上发现了问题所在,以下是Linux部分的官方文档 Linux
This can happen if you are install node-sass as
root
, or globally withsudo
. This is a security feature ofnpm
. You should always avoid runningnpm
assudo
because install scripts can be unintentionally malicious. Please check npm documentation on fixing permissions.
If you must however, you can work around this error by using the--unsafe-perm
flag with npm install i.e.前端$ sudo npm install --unsafe-perm -g node-sassIf this didn't solve your problem please open an issue with the output from our debugging script.java
下面是文档原文node
If you see an EACCES error when you try to install a package globally, read this chapter. This error can be avoided if you change the directory where npm is installed. To do this, either:
Reinstall npm with a version manager (recommended),
or
Change npm's default directory manually.
它说:若是你尝试安装一个全局的包,遇到了权限的错误,应该读读这一章.若是npm被安装的时候你改变了npm的目录,这个错误就会被避免(- 言下之意,就是让你改目录,就能够避免不能操做/usr/local/底下的内容了,你或者能够改变目录的权限 chmod [mode] dir
,效果应该同样的,我没试过,并且官方也没说),要想作到这个,要么用版本管理工具重装npm(- 官方推荐的),要么就手动改变npm的默认目录(我用的这个).git
If you are using npm version 5.2 or greater, explore tools such as npx to circumvent permissions issues.
若是你的npm版本是5.2以上,能够用npx(又是好尴尬,我有npx,也不会用.....)程序员
Back-up your computer before moving forward.
Make a directory for global installations:githubmkdir ~/.npm-globalConfigure npm to use the new directory path:shell
npm config set prefix '~/.npm-global'Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATHBack on the command line, update your system variables:
source ~/.profileInstead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
NPM_CONFIG_PREFIX=~/.npm-global
.npm-global
隐藏得太深了,ctrl+H
都看不到它,我就采用了阮一峰大神的方法,方法仍是要用大神的博客的方法或者官方的啊.首先,在主目录下新建配置文件.npmrc,而后在该文件中将prefix变量定义到主目录下面。 prefix = /home/yourUsername/npm 而后在主目录下新建npm子目录。 mkdir ~/npm 此后,全局安装的模块都会安装在这个子目录中,npm也会到~/npm/bin目录去寻找命令。 最后,将这个路径在.bash_profile文件(或.bashrc文件)中加入PATH变量。 export PATH=~/npm/bin:$PATH
npm i -g node-sass
# 卸载全局模块 $ npm uninstall [package name] -global
1. 必定不要用sudo安装,先手动改npm的目录
2. 更改.npmrc 和 .bashrc
3. npm i -g node-sass
4. 英语多学点,文档多看点,命令行多用点.
node-sass -wr scss -o css