如何安装sass

安装Sass和Compass

sass基于Ruby语言开发而成,因此安装sass前需要安装Ruby。(注:mac下自带Ruby无需在安装Ruby!)

window下安装SASS首先需要安装Ruby,先从官 下载Ruby并安装。安装过程中请注意勾选Add Ruby executables to your PATH添加到系统环境变量。如下图:

// 1.删除原gem源
gem sources –remove https://rubygems.org/
// 2.添加国内淘宝源
gem sources -a https://ruby.taobao.org/
// 3.打印是否替换成功
gem sources -l
// 4.更换成功后打印如下
*** CURRENT SOURCES ***

编译sass

sass编译有很多种方式,如命令行编译模式、sublime插件SASS-Build、编译软件koala、前端自动化软件codekit、Grunt打造前端自动化工作流grunt-sass、Gulp打造前端自动化工作流gulp-ruby-sass等。

命令行编译

// 单文件转换命令
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。

// 编译格式
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

命令行编译配置选项

//未编译样式
.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 编译排版格式

/命令行内容/
sass style.scss:style.css –style expanded
/编译过后样式/
.box {
width: 300px;
height: 400px;
}
.box-title {
height: 30px;
line-height: 30px;
}

compact 编译排版格式

/命令行内容/
sass style.scss:style.css –style compact
/编译过后样式/
.box { width: 300px; height: 400px; }
.box-title { height: 30px; line-height: 30px; }

compressed 编译排版格式

/命令行内容/
sass style.scss:style.css –style compressed
/编译过后样式/
.box{width:300px;height:400px}.box-title{height:30px;line-height:30px}

软件方式编译

推荐koala&codekit,它们是优秀的编译器,界面清晰简洁,操作起来也非常简单。鉴于koala是免费编译器


声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年10月8日
下一篇 2018年10月8日

相关推荐