當前位置:首頁 » 編程軟體 » nodesass編譯

nodesass編譯

發布時間: 2022-06-17 13:16:30

⑴ nodejs 編譯 sass 可以不用ruby嗎

Nodejs是一個
伺服器端
JavaScript
解釋器
,它將改變伺服器應該如何工作的概念。它的目標是幫助程序員構建高度可伸縮的應用程序,編寫能夠處理數萬條同時連接到一個(只有一個)
物理機
的連接代碼。

⑵ 有sass-loader還需要node-sass嗎

要的。因為 sass-loader 包中loader.js文件中有引包。

⑶ 為什麼我的sass 不會自動編譯成css

Webstorm是一個很牛叉的IDE,現在工作每天都是用它了。 最近開始用SASS,LESS等來寫CSS,而在Webstorm中,它自帶一個File Watchers功能,設置一下,即可實時編譯SASS,LESS等。 LESS的實時編譯很簡單,在node平台安裝一下即可。

⑷ node-sass使用python2

可以使用
nodesass是一個庫,它將Node.js綁定到LibSass【流行樣式表預處理器Sass的C版本】,它允許用戶以令人難以置信的速度將【.scss】文件本地編譯為css,並通過連接中間件自動編譯。Sass是一種預處理器腳本語言,可以解釋或編譯成層疊樣式表(CSS)。

⑸ 如何使用Node.js編寫命令工具

Node 給前端開發帶來了很大的改變,促進了前端開發的自動化,我們可以簡化開發工作,然後利用各種工具包生成生產環境。如運行sass src/sass/main.scss dist/css/main.css即可編譯 Sass 文件。
在實際的開發過程中,我們可能會有自己的特定需求,
那麼我們得學會如何創建一個Node命令行工具。
hello world

老規矩第一個程序為hello world。在工程中新建bin目錄,在該目錄下創建名為helper的文件,具體內容如下:
#!/usr/bin/env node console.log('hello world');

修改helper文件的許可權:
$ chmod 755 ./bin/helper

執行helper文件,終端將會顯示hello world:
$ ./bin/helperhello world

符號鏈接

接下來我們創建一個符號鏈接,在全局的node_moles目錄之中,生成一個符號鏈接,指向模塊的本地目錄,使我們可以直接使用helper命令。

在工程的package.json文件中添加bin欄位:
{ "name": "helper", "bin": { "helper": "bin/helper" }}

在當前工程目錄下執行npm link命令,為當前模塊創建一個符號鏈接:
$ npm link /node_path/bin/helper -> /node_path/lib/node_moles/myMole/bin/helper/node_path/lib/node_moles/myMole -> /Users/ipluser/myMole

現在我們可以直接使用helper命令:
$ helperhello world

commander模塊

為了更高效的編寫命令行工具,我們使用TJ大神的commander模塊。
$ npm install --save commander

helper文件內容修改為:
#!/usr/bin/env node var program = require('commander'); program .version('1.0.0') .parse(process.argv);

執行helper -h和helper -V命令:
$ helper -h Usage: helper [options] Options: -h, --help output usage information -V, --version output the version number $ helper -V1.0.0

commander模塊提供-h, --help和-V, --version兩個內置命令。
創建命令

創建一個helper hello <author>的命令,當用戶輸入helper hello ipluser時,終端顯示hello ipluser。修改helper文件內容:
#!/usr/bin/env node var program = require('commander'); program .version('1.0.0') .usage('<command> [options]') .command('hello', 'hello the author') // 添加hello命令 .parse(process.argv);

在bin目錄下新建helper-hello文件:
#!/usr/bin/env node console.log('hello author');

執行helper hello命令:
$ helper hello ipluserhello author

解析輸入信息
我們希望author是由用戶輸入的,終端應該顯示為hello ipluser。修改helper-hello文件內容,解析用戶輸入信息:
#!/usr/bin/env node var program = require('commander'); program.parse(process.argv); const author = program.args[0]; console.log('hello', author);

再執行helper hello ipluser命令:
$ helper hello ipluserhello ipluser

哦耶,終於達到完成了,但作為程序員,這還遠遠不夠。當用戶沒有輸入author時,我們希望終端能提醒用戶輸入信息。
提示信息
在helper-hello文件中添加提示信息:
#!/usr/bin/env node var program = require('commander'); program.usage('<author>'); // 用戶輸入`helper hello -h`或`helper hello --helper`時,顯示命令使用例子program.on('--help', function() { console.log(' Examples:'); console.log(' $ helper hello ipluser'); console.log();}); program.parse(process.argv);(program.args.length < 1) && program.help(); // 用戶沒有輸入信息時,調用`help`方法顯示幫助信息 const author = program.args[0]; console.log('hello', author);

執行helper hello或helper hello -h命令,終端將會顯示幫助信息:$ helper hello Usage: helper-hello <author> Options: -h, --help output usage information Examples: $ helper hello ipluser $ helper hello -h Usage: helper-hello <author> Options: -h, --help output usage information Examples: $ helper hello ipluser

⑹ 現在sass軟體有什麼好做的

1、安裝sass

1.安裝ruby

因為sass是用ruby語言寫的,所以需要安裝ruby環境
打開安裝包去安裝ruby,記住要勾選 下面選項來配置環境路徑

  • Add Ruby executables to your PATH
    安裝完成之後繼續下一步操作

  • 2.安裝sass

    在cmd里通過gem安裝sass

    gem是ruby的包管理工具,類似於nodejs 的npm

  • gem install sass1

  • 這個時候如果不翻牆的話是會出問題的,因為:
    由於國內網路原因(你懂的),導致rubygems.org存放在 Amazon S3 上面的資源文件間歇性連接失敗。這時候我們可以通過gem sources命令來配置源,先移除默認的https://rubygems.org源,然後添加淘寶的源https://ruby.taobao.org/,然後查看下當前使用的源是哪個,如果是淘寶的,則表示可以輸入sass安裝命令gem install sass了

  • $ gem sources --remove https://rubygems.org/

  • $ gem sources -a https://ruby.taobao.org/ 【如果你系統不支持https,請將淘寶源更換成:gem sources -a http://gems.ruby-china.org】

  • $ gem sources -l

  • *** CURRENT SOURCES ***

  • https://ruby.taobao.org

  • # 請確保只有 ruby.taobao.org

  • $ gem install sass1234567

  • 安裝好之後執行sass -v就可以看到sass的版本了
    實在實在不行,就安裝離線文件吧,但是失敗率也很高
    gem install ./…/sass-3.4.22.gem

    2、編譯sass文件的方式

    1.命令行編譯

    可以通過cmd命令行執行sass方法來編譯
    例如:

  • sass scss/a.scss:css/a.css1

  • sass 後面寫要編譯的sass文件的路徑,『:』後面寫的是
    要輸出的目錄及名字

  • 需要注意的是:必須有這個文件夾才能在裡面生成css
    這樣的話寫一句執行一次編譯一次有些太麻煩
    可以開啟一個watch來監聽文件變化來進行編譯

  • sass --watch scss:css1

  • –watch表示要監聽 :前後的兩個都是文件夾,表示scss文件夾的文件改變就編譯到css文件夾

    2.其他方式編譯

    除了命令行工具其實還可以用考拉、gulp等工具進行編譯,但是ruby和sass是必須要安裝的
    考拉的方式就不多做介紹了,大家i自己去看一下
    gulp的話呢是需要gulp-sass的模塊來編譯,使用方式類似於gulp-less
    這里是網址,點擊查看

    3、sass四種風格

    sass編譯的格式

    sass編譯輸出的css有四種格式

  • nested 嵌套

  • compact 緊湊

  • expanded 擴展

  • compressed 壓縮

  • 這些樣式會影響輸出的css的格式
    簡單介紹一下:
    css默認輸出的嵌套

  • ul{

  • font-size:15px;

  • li{

  • list-style:none;

  • }

  • }123456

  • —》

  • ul {

  • font-size: 15px; }

  • ul li {

  • list-style: none; }1234

  • 緊湊compact
    在編譯的時候需要執行

  • sass --watch scss:css --style compact1

  • 這個時候輸出的代碼就是

  • ul { font-size: 15px; }

  • ul li { list-style: none; padding: 5px; }12

  • compressed 壓縮
    在編譯的時候需要執行

  • sass --watch scss:css --style compressed1

  • —>

  • ul{font-size:15px}ul li{list-style:none;animation:all 0.4s}1

  • expanded 擴展
    更像是平時寫的css一樣
    在編譯的時候需要執行

  • sass --watch scss:css --style expanded1

  • —>

  • ul {

  • font-size: 15px;

  • }

  • ul li {

  • list-style: none;

  • animation: all 0.3s;

  • }1234567

  • compressed 壓縮
    更像是平時寫的css一樣
    在編譯的時候需要執行

  • sass --watch scss:css --style compressed1

  • —>

  • .a{width:100px;height:100px;border:1px solid red}.a .b{background:red}1

  • 4、sass與scss

    sass的兩個語法版本

    sass一開始用的是一種縮進式的語法格式
    採用這種格式文件的後綴名是.sass
    在sass3.0版本後我們常用的是sassy css語法,擴展名是.scss,更接近與css語法

    兩個版本的區別

  • 後綴名不同 .sass和.scss

  • 語法不同,請看下面
    新版:

  • /*新版本

  • 多行文本注釋*/

  • //新版本

  • //單行文本注釋

  • @import "base";

  • @mixin alert{

  • color:red;

  • background:blue;

  • }

  • .alert-warning{

  • @include alert;

  • }

  • ul{

  • font-size:15px;

  • li{

  • list-style:none;

  • }

  • }123456789101112131415161718

  • 老版本:

  • /*新版本

  • 多行文本注釋

  • //新版本

  • 單行文本注釋

  • @import "base"

  • =alert

  • color:red

  • background:blue

  • .alert-warning

  • +alert

  • ul

  • font-size:15px

  • li

  • list-style:none1234567891011121314

  • 5、變數、嵌套、混合、繼承拓展

    變數的意義

    在sass里我們可以定義多個變數來存放顏色、邊框等等的樣式,這樣就可以在下面想要使用樣式的時候使用變數了
    這樣的優點就是便於維護,更改方便

    變數的使用

    可以通過$來定義變數,在變數名字中可以使用-和_來作為連接,並且-和_是可以互通的,就是用起來一模一樣。
    變數的值可以是字元串、數字、顏色等等,在變數里還可以使用其他變數,使用的時候直接寫變數名就好了
    例如

  • $primary-color:#ff6600;

  • $primary-border:1px solid $primary_color;

  • div.box{

  • background:$primary-color;

  • }

  • h1.page-header{

  • border:$primary-border;

  • }12345678

  • —》

  • div.box {

  • background: #ff6600;

  • }

  • h1.page-header {

  • border: 1px solid #ff6600;

  • }123456

  • 嵌套的使用

    合理的使用嵌套語法,可以使我們編寫代碼更為快捷
    假設我們想寫這樣的css:

  • .nav {

  • height: 100px;

  • }

  • .nav ul {

  • margin: 0;

  • }

  • .nav ul li {

  • float: left;

  • list-style: none;

  • padding: 5px;

  • }1234567891011

  • 在sass里我們可以這樣寫

  • .nav{

  • height:100px;

  • ul{

  • margin:0;

  • li {

  • float:left;

  • list-style:none;

  • padding:5px;

  • }

  • }

  • }1234567891011

  • 大家會發現,寫出來的代碼父和子之間都有空格隔開,如果我們需要給a加上偽類的話我們這樣寫

  • .nav{

  • height:100px;

  • a{

  • color:#fff;

  • :hover{

  • color:#ff6600;

  • }

  • }

  • }123456789

  • 在裡面就會出現這樣的情況

  • .nav a :hover {

  • color: #ff6600;

  • }123

  • 我們發現在a和:hover之間有了空格,這樣是不好的,所以我們需要在寫的時候在:hover之前把a加上,這樣就需要用到在之類里引用父類選擇器的方式,我們可以用&符號代替父類
    例如:

  • .nav{

  • height:100px;

  • a{

  • color:#fff;

  • &:hover{

  • color:#ff6600;

  • }

  • }

  • }123456789

  • 這樣就好了,下面來個完整的代碼:

  • .nav{

  • height:100px;

  • ul{

  • margin:0;

  • li{

  • float:left;

  • list-style:none;

  • padding:5px;

  • }

  • a{

  • display:block;

  • color:#000;

  • &:hover{

  • color:#f60;

  • background:red;

  • }

  • }

  • }

  • & &-text{

  • font-size:15px;

  • }

  • }

  • -----》

  • .nav {

  • height: 100px;

  • }

  • .nav ul {

  • margin: 0;

  • }

  • .nav ul li {

  • float: left;

  • list-style: none;

  • padding: 5px;

  • }

  • .nav ul a {

  • display: block;

  • color: #000;

  • }

  • .nav ul a:hover {

  • color: #f60;

  • background: red;

  • }

  • .nav .nav-text {

  • font-size: 15px;

  • }

  • 嵌套屬性

    我們可以把一些個復合屬性的子屬性來嵌套編寫,加快編寫速度,例如

  • body{

  • font:{

  • family:Helvitica;

  • size:15px;

  • weight:bold;

  • }

  • }

  • .nav{

  • border:1px solid red{

  • left:none;

  • right:none;

  • }

  • }

  • .page-next{

  • transition:{

  • property:all;

  • delay:2s;

  • }

  • }12345678910111213141516171819

  • -----》

  • body {

  • font-family: Helvitica;

  • font-size: 15px;

  • font-weight: bold;

  • }

  • .nav {

  • border: 1px solid red;

  • border-left: none;

  • border-right: none;

  • }

  • .page-next {

  • transition-property: all;

  • transition-delay: 2s;

  • }1234567891011121314

  • mixin 混合

    你可以把它想像成一個有名字的定義好的樣式
    每一個mixin都有自己的名字,類似於js里的函數定義方法如下

  • @mixin 名字(參數1,參數2...){

  • ...

  • }123

  • 使用方法是在其他選擇器css樣式里通過@include引入,其實就相當於將mixin里的代碼寫入到這個選擇器的css里,如下:

  • @mixin alert {

  • color:#f60;

  • background-color:#f60;

  • a{

  • color:pink;

  • }

  • &-a{

  • color:red;

  • }

  • }

  • .alert-warning{

  • @include alert;

  • }12345678910111213

  • -----》

  • .alert-warning {

  • color: #f60;

  • background-color: #f60;

  • }

  • .alert-warning a {

  • color: pink;

  • }

  • .alert-warning-a {

  • color: red;

  • }12345678910

  • 剛才是沒有參數的mixin,mixin也可以擁有參數,需要注意的是:

  • 形參的名字前要加$

  • 傳參的時候只寫值的話要按順序傳

  • 傳參的時候不想按順序的話需要加上形參名字
    例如:

  • @mixin alert($color,$background) {

  • color:$color;

  • background-color:$background;

  • a{

  • color:darken($color,10%);//把顏色加深百分之十

  • }

  • }

  • .alert-warning{

  • @include alert(red,blue);

  • }

  • .alert-info{

  • @include alert($background:red,$color:blue);

  • }12345678910111213

  • ------》

  • .alert-warning {

  • color: red;

  • background-color: blue;

  • }

  • .alert-warning a {

  • color: #cc0000;

  • }

  • .alert-info {

  • color: blue;

  • background-color: red;

  • }

  • .alert-info a {

  • color: #0000cc;

  • }1234567891011121314

  • 繼承拓展 extend

    如果我們有一個選擇器想要擁有另一個選擇所有的東西,不管是樣式還是子元素等等,可以使用@extend來繼承
    大家需要注意的是,++b繼承a的時候,a的子元素設置了樣式,也會給b的子元素設置樣式++,達到完全一樣的情況,例如:

  • .alert {

  • padding:5px;

  • }

  • .alert a {

  • font:{

  • weight:bold;

  • size:15px;

  • }

  • }

  • .alert-info {

  • @extend .alert;

  • backgournd:skyblue;

  • }12345678910111213

  • ----》

  • .alert, .alert-info {

  • padding: 5px;

  • }

  • .alert a, .alert-info a {

  • font-weight: bold;

  • font-size: 15px;

  • }

  • .alert-info {

  • backgournd: skyblue;

  • }12345678910

  • partials

    在以前咱們編寫css的時候,一個css引入另一個css需要使用@import,其實這是不好的,會多發一次http請求,影響咱們站點的響應速度。
    在sass里,咱們可以把小的sass文件分出去,叫做partials,在某個sass里通過@import 『partials名』去引入,注意路徑喲,這樣的話就可以把partials里的代碼引到咱們大的sass里一起編譯

  • 需要注意的是 partials的文件名前要加_

  • _base.sass :

  • body{

  • margin:0;

  • padding:0;

  • }1234

  • style.sass :

  • @import "base";

  • .alert {

  • padding:5px;

  • }

  • .alert a {

  • font:{

  • weight:bold;

  • size:15px;

  • }

  • }

  • .alert-info {

  • @extend .alert;

  • backgournd:skyblue;

  • }1234567891011121314

  • ----------->

  • body {

  • margin: 0;

  • padding: 0;

  • }

  • .alert, .alert-info {

  • padding: 5px;

  • }

  • .alert a, .alert-info a {

  • font-weight: bold;

  • font-size: 15px;

  • }

  • .alert-info {

  • backgournd: skyblue;

  • }1234567891011121314

  • 這樣的話我們就可以把模塊化的思想引入到sass里了

    comment注釋

    sass里的注釋有三種

  • 多行注釋

  • 單行注釋

  • 強制注釋
    多行注釋:壓縮後不會出現在css里 /*/
    單行注釋: 不會出現在css里 //
    強制注釋:壓縮後也會出現在css里 /! */

  • 6、數據類型與函數

    數據類型

    在sass里有數字、字元串、列表、顏色等類型
    在cmd里 輸入

  • sass -i1

  • 就會進入到交互模式,輸入的計算可以馬上得到結果
    type-of()可以用來得到數據類型,如:

  • type-of(5) -> number1

  • 注意數字類型的可以包含單位,如:

  • type-of(5px) -> number1

  • 字元串類型:

  • type-of(hello) -> string

  • type-of('hello') -> string12

  • list類型:

  • type-of(1px solid red) -> list

  • type-of(5px 10px) -> list12

  • 顏色:

  • type-of(red) -> color

  • type-of(rgb(255,0,0) -> color

  • type-of(#333) -> color123

  • number 計算

  • 2+9 -》10

  • 2*8 -》16

  • (8/2) ->4 //除法要寫括弧123

  • 也可以包含單位

  • 5px + 5px -> 10px

  • 5px -2 ->3px

  • 5px *2 ->10px

  • 5px * 2px ->10px*px //這樣就不對了喲

  • (10px/2px) -> 5//除法單位取消

  • 3+2*5px->13px123456

  • 好吧,都是一些小學的數學題,很簡單對吧

    處理數字的函數

    絕對值

  • abs(10) -> 10;

  • abs(10px) -> 10px;

  • abs(-10px) -> 10px;123

  • 四捨五入相關

  • round(3.4)->3 //四捨五入

  • round(3.6)->4

  • ceil(3.2)->4 //向上取整

  • ceil(3.6)->4

  • floor(3.2)->3 //向下取整

  • floor(3.9)->3

  • percentage(600px/1000px) ->65% //百分之

  • min(1,2,3) -> 1 //最小值

  • max(2,3,4,5) -> 5 //最大值123456789

  • 字元串相關

  • //帶引號和不帶引號的字元串想加為帶引號的字元串

  • "a" + b ->"ab"

  • a + "b" ->"ab"

  • //字元串+數字

  • "ab" + 1 ->"ab1"

  • //字元串 - 和 / 字元串

  • "a" - b ->"a-b"

  • "a" / b ->"a/b"

  • //注意字元串不能相乘123456789

  • 字元串函數

    大寫:

  • $word:"hello";

  • to-upper-case($word) -> "HELLO"12

  • 小寫:

  • $word:"Hello";

  • to-lower-case($word) -> "hello"12

  • 得到length:

  • $word:"Hello";

  • str-length($word) -> 512

  • 得到字元串在字元串里的位置:

  • $word:"Hello";

  • str-index($word,"el") -> 212

  • 字元串中插入字元串:

  • $word:"Hello";

  • str-insert($word,"aa",2) -> "Haaello"12

  • 顏色相關

    在sass里除了關鍵字、十六進制、rgb和rgba之外還有一種顏色是HSL
    分別表示的是 色相 0-360(deg) 飽和度 0-100% 明度 0-100%
    例如:

  • body {

  • background-color:hsl(0,100%,50%);

  • }

  • -》

  • body {

  • background-color: red;

  • }1234567

  • body {

  • background-color:hsl(60,100%,50%);

  • }

  • -》

  • body {

  • background-color: yellow;

  • }1234567

  • 也可以有透明喲

  • body {

  • background-color:hsl(60,100%,50%,0.5);

  • }

  • -》

  • body {

  • background-color: rgba(255,255,0,0.5);

  • }1234567

  • 顏色函數

    lighten函數和darken函數可以把顏色加深或減淡,即調整明度,第一個參數為顏色,第二個參數為百分比,例如:

  • $color:#ff0000;

  • $light-color:lighten($color,30%);

  • $dark-color:darken($color,30%);

  • .a{

  • color:$color;

  • background:$light-color;

  • border-color:$dark-color;

  • }12345678

  • —》

  • .a {

  • color: #ff0000;

  • background: #ff9999;

  • border-color: #660000;

  • }12345

  • saturate和desaturate函數可以調整顏色的純度

  • $color:hsl(0,50%,50%);

  • $saturate-color:saturate($color,50%);

  • $desaturate-color:desaturate($color,30%);

  • .a{

  • color:$color;

  • background:$saturate-color;

  • border-color:$desaturate-color;

  • }12345678

  • –》

  • .a {

  • color: #bf4040;

  • background: red;

  • border-color: #996666;

  • }12345

  • 用transparentize來讓顏色更透明
    用opatify來讓顏色更不透明

  • $color:rgba(255,0,0,0.5);

  • $opacify-color:opacify($color,0.3);

  • $transparentize-color:transparentize($color,0.3);

  • .a{

  • color:$color;

  • background:$opacify-color;

  • border-color:$transparentize-color;

  • }12345678

  • —》

  • .a {

  • color: rgba(255, 0, 0, 0.5);

  • background: rgba(255, 0, 0, 0.8);

  • border-color: rgba(255, 0, 0, 0.2);

  • }12345

  • 列表類型

    在sass里,用空格或者逗號隔開的值就是列表類型
    如:

  • 1px solid red

  • Courier,microsoft yahei12

  • 列表函數

    sass里的列表類似與數組

  • 獲取列表的長度

  • length(5px 10x) 2

  • 獲取列表中的第幾個元素

  • nth(5px 10px,2) 10px

  • 獲取一個元素在一個列表裡的下標

  • index(1px solid red,solid) 2

  • 給列表裡加入新的元素

  • append(5px 10px,5px) 5px 10px 5px

  • 連接兩個列表

  • join(5px 10px,5px 0) 5px 10px 5px 012345678910

  • map類型

    sass里的map類型類似與js里的object

  • $map:(key1:value1,key2:value2,key3:value3);1

  • map 函數

  • //定義一個map

  • $color:(light:#ffffff,dark:#000000);

  • //獲取map 的length

  • length($color) ->2

  • //得到map里key對應的值

  • map-get($color,dark) ->#000000

  • 獲取map里的所有鍵的列表

  • map-keys($color) ->("light","dark") //列表類型

  • 獲取map里的所有值的列表

  • map-values($color) -> ("#ffffff","#000000") //列表類型

  • 判斷map里是否含有這個key

  • map-has-key($color,light) ->true

  • 給map里添加鍵值對

  • map-merge($color,(light-gray:#cccccc))

  • ->(light:#ffffff,dark:#000000,light-gray:#cccccc)

  • 移除map里的某個鍵值對

  • map-remove($colors,light) ->(dark:#000000,light-gray:#cccccc)1234567891011121314151617

  • boolean類型

    在sass里通過> < 比較得到的值就是布爾值 true 和false

  • 5px>3px -> true

  • 5px<2px -> false12

  • 在sass里也可以有或 且 非
    且:

  • (5px > 3px) and (5px < 2px) -> false

  • (5px > 3px) and (5px > 2px) -> true12

  • 或:

  • (5px > 3px) or (5px < 2px) -> true

  • (5px < 3px) and (5px > 2px) -> false12

  • 非:

  • not(5px>3px) -> false1

  • interpolation

    在sass里可以通過interpolation的方式來在變數名和屬性名上拼接變數值,例如

  • $name:"info";

  • $attr:"border";

  • .alert-#{$name}{

  • #{$attr}-color:red;

  • }12345

  • ---->

  • .alert-info {

  • border-color: red;

  • }123

  • 7、分支結構、循環結構、函數

    分支結構

    在sass里,可以使用@if讓我們根據一些條件來應用特定的樣式
    結構:

  • @if 條件 {


  • }123

  • 如果條件為真的話,括弧里的代碼就會釋放出來
    例如:

  • $use-refixes:true;

  • .rounded{

  • @if $use-refixes {

  • -webkit-border-radius:5px;

  • -moz-border-radius:5px;

  • -ms-border-radius:5px;

  • -o-border-radius:5px;

  • }

  • border-radius:5px;

  • }12345678910

  • —>

  • .rounded {

  • -webkit-border-radius: 5px;

  • -moz-border-radius: 5px;

  • -ms-border-radius: 5px;

  • -o-border-radius: 5px;

  • border-radius: 5px;

  • }1234567

  • 如果是另外一種情況

  • $use-refixes:false;1

  • —》

  • .rounded {

  • border-radius: 5px;

  • }123

  • if else在sass里的寫法是:

  • body{

  • @if $theme == dark {

  • background:black;

  • } @else if $theme == light {

  • background:white;

  • } @else {

  • background:gray;

  • }

  • }123456789

  • for循環

    在sass里的for循環是這樣的

  • @for $var form <開始值> through <結束值> {

  • ...

  • }123

  • 還有一種是

  • @for $var form <開始值> to <結束值> {

  • ...

  • }123

  • 注意,開始值和結束值的關系可以是升序也可以是倒序,但是每次只能+1或者-1
    這兩種有什麼區別呢?
    區別就是 from 1 to 4 的話是執行三次,i的變化是 1 2 3
    from 1 through 4 的話是執行四次,i的變化是 1 2 3 4
    如:
    from to

  • $columns:4;

  • @for $i from 1 to $columns{

  • .col-#{$i}{

  • width:100% / $columns * $i;

  • }

  • }123456

  • —》

  • .col-1 {

  • width: 25%;

  • }

  • .col-2 {

  • width: 50%;

  • }

  • .col-3 {

  • width: 75%;

  • }123456789

  • from through

  • $columns:4;

  • @for $i from 1 through $columns{

  • .col-#{$i}{

  • width:100% / $columns * $i;

  • }

  • }123456

  • —>

  • .col-1 {

  • width: 25%;

  • }

  • .col-2 {

  • width: 50%;

  • }

  • .col-3 {

  • width: 75%;

  • }

  • .col-4 {

  • width: 100%;

  • }123456789101112

  • each 遍歷list類型

    在sass里可以利用each方法來遍歷咱們的list類型的數據
    list類型在js里類似於數組,那麼each類似於for in遍歷,結構如下:

  • @each $item in $list{

  • ...

  • }123

  • 例如:

  • $colors:success error warning;

  • $map:(success:green,warning:yellow,error:red);

  • @each $color in $colors{

  • .bg-#{$color}{

  • background:map-get($map,$color);

  • }

  • }1234567

  • —>

  • .bg-success {

  • background: green;

  • }

  • .bg-error {

  • background: red;

  • }

  • .bg-warning {

  • background: yellow;

  • }123456789

  • @while 循環

    在sass里,擁有@while循環,比@for會更好用一些,@for循環只能從一個數到另一個數變化之間執行,每次變化都是1,while設置循環結構的話更為靈活;
    結構:

  • @while 條件{


  • }123

  • eq:

  • $i:6;

  • @while $i>0{

  • .item-#{$i}{

  • width:$i*5px;

  • }

  • $i:$i - 2;

  • }1234567

  • 注意:$i - 2 需要用空格隔開喲
    ---------》

  • .item-6 {

  • width: 30px;

  • }

  • .item-4 {

  • width: 20px;

  • }

  • .item-2 {

  • width: 10px;

  • }123456789

  • 自定義函數

    在sass里也可以定義函數,並且也可以有返回值
    結構:

  • @function 名稱 (參數1,參數2){

  • @return ...

  • }123

  • 例如,我們做一個返回map里key對應的值的函數:

  • $colors:(light:#ffffff,dark:#000000,gray:#555555);

  • @function color($key){

  • @return map-get($colors,$key);

  • }

  • body{

  • background:color(light);

  • color:color(dark);

  • border-color:color(gray);

  • }123456789

  • —》

  • body {

  • background: #ffffff;

  • color: #000000;

  • border-color: #555555;

  • }

⑺ node.js安裝好後用什麼編譯

你想編譯什麼?
nodejs可以直接運行js文件的,在對應的文件夾下命令行輸入node demo.js,即可執行demo.js文件。
使用node-gpy可以編譯c++寫的模塊。
nodejs中還有編譯一些其他腳本語言了模塊,比如less、sass、ts

⑻ webstorm怎麼編譯sass

這個文件夾應該是webstorm這樣的編輯器創建的,我猜想它可能用於記錄一些project項目配置等,比如:查詢索引。

⑼ nodejs服務端渲染怎麼處理less或sass

1、安裝Sublime插件(1)安裝LESS插件:因為Sublime不支持Less語法高亮,所以,先安裝這個插件,方法1:ctrl+shift+p>installPackage>輸入less按Enter方法2:直接下載後解壓文件放到插件文件夾下(首選項-瀏覽插件打開文件夾)下載地址:/timdouglas/sublime-less2css解壓文件放到插件文件夾下但是我們還要讓sublime支持less並自動編譯,所以還需以下步驟:2、安裝Node.js首先先配置一下環境,less需要nodejs支持,所以我們先要安裝一下nodejs到nodejs官網下載就可以了:3、安裝less運行-cmd:輸入命令行:npminstallless-g-g代表著全局安裝less之後在Sublime裡面建less文件時,會有一個錯誤LESS:-css這是因為還需要一個插件less-plugin-clean-css插件的安裝命令行為:npminstallless-plugin-clean-css-g接著重啟一下sublime,就搞定啦!

⑽ node-sass編譯不過怎麼辦

添加一個環境變數「PYTHON」,指向我機器上 python2 的可執行文件(因為沒有安裝在默認的"C:\PYTHON27\"路徑下,導致node-nyp找不到它)

熱點內容
我的世界伺服器圈太大了怎麼辦 發布:2025-05-17 11:15:21 瀏覽:613
便宜的免費雲伺服器 發布:2025-05-17 11:08:50 瀏覽:775
中國頂級dhcp解析伺服器地址 發布:2025-05-17 11:06:27 瀏覽:32
php轉義html 發布:2025-05-17 11:04:00 瀏覽:566
鋼筋籠加密區規范 發布:2025-05-17 10:59:50 瀏覽:3
我的世界網易手機版主播伺服器房號 發布:2025-05-17 10:40:59 瀏覽:226
豎編譯 發布:2025-05-17 09:56:08 瀏覽:229
編程畫飛機 發布:2025-05-17 09:54:03 瀏覽:803
手機如何解鎖密碼屏幕鎖怎麼刪除 發布:2025-05-17 09:52:04 瀏覽:125
網路無法訪問網頁 發布:2025-05-17 09:51:40 瀏覽:651