sass
編譯有不少種方式,如命令行編譯模式、sublime插件SASS-Build
、編譯軟件koala
、前端自動化軟件codekit
、Grunt打造前端自動化工做流grunt-sass
、Gulp打造前端自動化工做流gulp-ruby-sass
等。css
//單文件轉換命令 sass input.scss output.css //單文件監聽命令 sass --watch input.scss:output.css //若是你有不少的sass文件的目錄,你也能夠告訴sass監聽整個目錄: sass --watch app/sass:public/stylesheets
命令行編譯sass
有配置選項,如編譯事後css排版、生成調試map、開啓debug信息等,可經過使用命令sass -v
查看詳細。咱們通常經常使用兩種--style
--sourcemap
。html
//編譯格式 sass --watch input.scss:output.css --style compact //編譯添加調試map sass --watch input.scss:output.css --sourcemap //選擇編譯格式並添加調試map sass --watch input.scss:output.css --style expanded --sourcemap //開啓debug信息 sass --watch input.scss:output.css --debug-info
--style
表示解析後的css
是什麼排版格式;nested
expanded
compact
compressed
。--sourcemap
表示開啓sourcemap
調試。開啓sourcemap
調試後,會生成一個後綴名爲.css.map
文件。//未編譯樣式 .box { width: 300px; height: 400px; &-title { height: 30px; line-height: 30px; } }
# nested 編譯排版格式前端
/*命令行內容*/ sass style.scss:style.css --style nested /*編譯事後樣式*/ .box { width: 300px; height: 400px; } .box-title { height: 30px; line-height: 30px; }
# expanded 編譯排版格式gulp
/*命令行內容*/ sass style.scss:style.css --style expanded /*編譯事後樣式*/ .box { width: 300px; height: 400px; } .box-title { height: 30px; line-height: 30px; }
# compact 編譯排版格式sass
/*命令行內容*/ sass style.scss:style.css --style compact /*編譯事後樣式*/ .box { width: 300px; height: 400px; } .box-title { height: 30px; line-height: 30px; }
# compressed 編譯排版格式ruby
/*命令行內容*/ sass style.scss:style.css --style compressed /*編譯事後樣式*/ .box{width:300px;height:400px}.box-title{height:30px;line-height:30px}
這裏推薦koala&codekit,它們是優秀的編譯器,界面清晰簡潔,操做起來也很是簡單。鑑於koala是免費編譯器,簡單操做以下圖:app