官术网_书友最值得收藏!

Using Sass on the command line

You can run Sass on the command line to compile your Sass files directly into the CSS code.

Getting ready

In the Installing Sass for command line usage recipe of this chapter, you have already read how to install Sass. Linux users have to open a terminal, while Mac users have to run the Terminal.app, and Window users have to use the cmd command for command-line usage.

How to do it...

Use the following steps to find out how to compile your Sass code in the command line:

  1. Create a Sass template called first.scss that contains the following SCSS code:
    $color: orange;
    
    p {
      color: $color;
    }
  2. Then, run the following command in your console:
    sass first.scss
  3. You will find that the preceding command outputs the CSS code as it is shown here:
    p {
      color: orange; }

How it works...

Firstly, notice that the example code in this recipe uses the newer SCSS syntax for Sass. In the Writing Sass or SCSS recipe of this chapter, you can read why this book uses the SCSS syntax in favor of the original indented Sass syntax.

The sass command directly outputs the compiled CSS code to your console. To save the output in a file, you will have to set a second output argument, as follows:

sass first.scss first.css

The preceding command creates a new first.css CSS file that contains the compiled CSS code.

There's more...

When compiling your Sass templates into CSS files, Sass does not only create CSS files, but also a folder called .sass-cache. By default, Sass caches compile templates and partials. In the Working with partials recipe of this chapter, you can read what partials are. Caching of the compiled templates and partials makes recompiling after your changes faster.

You can use the --no-cache option to disable caching.

The --compass option makes Compass imports available and loads the project's configuration. You can read more about this option in the Extending Sass with Compass helper functions and more recipe of Chapter 6, Using Compass.

主站蜘蛛池模板: 灵石县| 湘潭市| 泸水县| 台安县| 大港区| 武宣县| 确山县| 安化县| 荃湾区| 沽源县| 建阳市| 林周县| 武平县| 金寨县| 溆浦县| 景东| 鄂托克旗| 梅河口市| 大厂| 富民县| 奉贤区| 榆林市| 泸州市| 鹰潭市| 札达县| 临漳县| 乌鲁木齐市| 青田县| 广西| 内黄县| 疏附县| 友谊县| 珠海市| 大田县| 壤塘县| 读书| 调兵山市| 长垣县| 莱阳市| 沅陵县| 拜泉县|