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