記錄一下安裝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