前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >编译sass

编译sass

作者头像
Qwe7
发布2022-05-13 07:44:58
6090
发布2022-05-13 07:44:58
举报
文章被收录于专栏:网络收集

sass安装

Ruby自带一个叫做RubyGems的系统,用来安装基于Ruby的软件。我们可以使用这个系统来 轻松地安装Sass和Compass。要安装最新版本的Sass和Compass,你需要输入下面的命令:

代码语言:javascript
复制
//安装如下(如mac安装遇到权限问题需加 sudo gem install sass)
gem install sass
gem install compass

在每一个安装过程中,你都会看到如下输出:

代码语言:javascript
复制
Fetching: sass-3.x.x.gem (100%)
Successfully installed sass-3.x.x
Parsing documentation for sass-3.x.x
Installing ri documentation for sass-3.x.x
Done installing documentation for sass after 6 secon
1 gem installed

安装完成之后,你应该通过运行下面的命令来确认应用已经正确地安装到了电脑中:

代码语言:javascript
复制
sass -v
Sass 3.x.x (Selective Steve)
 
compass -v
Compass 1.x.x (Polaris)
Copyright (c) 2008-2015 Chris Eppstein
Released under the MIT License.
Compass is charityware.
Please make a tax deductable donation for a worthy cause: http://umdf.org/compass

如下sass常用更新、查看版本、sass命令帮助等命令:

代码语言:javascript
复制
//更新sass
gem update sass
 
//查看sass版本
sass -v
 
//查看sass帮助
sass -h

编译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

--style表示解析后的css是什么排版格式;

sass内置有四种编译格式: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

代码语言:javascript
复制
/*编译过后样式*/
.box {
  width: 300px;
  height: 400px; }
  .box-title {
    height: 30px;
    line-height: 30px; }
expanded 编译排版格式
/*命令行内容*/
sass style.scss:style.css --style expanded

代码语言:javascript
复制
/*编译过后样式*/
.box {
  width: 300px;
  height: 400px;
}
.box-title {
  height: 30px;
  line-height: 30px;
}

compact 编译排版格式

代码语言:javascript
复制
/*命令行内容*/
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}

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档