๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ปSTUDY/SASS

[SASS] Node๋กœ sass ์‹œ์ž‘ํ•˜๊ธฐ

๋ฐ˜์‘ํ˜•

1. CLI๋กœ sass ์„ค์น˜

  1. Node.js ์„ค์น˜๊ฐ€ ๋˜์–ด ์žˆ์–ด์•ผ ๋จ.
  2. npm install sass -g ๋กœ CLI ์— ์„ค์น˜.

 

2. sass ๋ฒ„์ „ ํ™•์ธ

$ npm show sass version
$ sass --version

 

3. ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ์— scss -> css ๋ณ€ํ™˜

$ sass style.scss style.css

$ sass <๋ณ€ํ™˜ํ•  scss ํŒŒ์ผ๋ช…> <๋ณ€ํ™˜๋  css ํŒŒ์ผ๋ช…> ์ž…๋ ฅ.

ํด๋” ์•ˆ์— ์žˆ์„ ๊ฒฝ์šฐ,

$ sass scss/style.scss style.css

 

4. sass ๋ณด๊ธฐ , ๋๋‚ด๊ธฐ

--watch๋ผ๋Š” ํ”Œ๋ž˜๊ทธ๋ฅผ ๋„ฃ์–ด ํ•ด๋‹น ํŒŒ์ผ ์ž๋™์œผ๋กœ ๋ณ€ํ™˜.

$ sass --watch style.scss:style.css

์•„๋ž˜์ฒ˜๋Ÿผ ํด๋” ๋‚ด ๋ชจ๋“  ํŒŒ์ผ๋“ค์„ ์ปดํŒŒ์ผํ•  ์ˆ˜ ์žˆ๋‹ค. sass --watch <inputํด๋”>:<outputํด๋”>

$ sass --watch scss:css

 

sass ์‹ค์‹œ๊ฐ„ ์ปดํŒŒ์ผ ๋๋‚ด๋ ค๋ฉด ctrl + c

 

์ถ”๊ฐ€

sass๋ณด๊ธฐ + css ๋ณ€ํ™˜์Šคํƒ€์ผ

$ sass --watch scss/style.scss:css/style.css --style compact

 

5. sass ๋ณ€ํ™˜์Šคํƒ€์ผ

$ sass --style compact scss/style.scss css/style.css
  • ๋ณ€ํ™˜์Šคํƒ€์ผ

    • nested
    • expanded
    • compact
    • compressed
/* nested */
ul {
    font-family: arial;
    color: #333; }
ul li {
    display: inline-block; }

/* expanded */
ul {
    font-family: arial;
    color: #333;
}
ul li {
    display: inline-block;
}
/* compact */
ul { font-family: arial; color:#333; }
ul li { display: inline-block; }

/* compressed */
ul{font-family:arial;color:#333;}ul li{display:inline-block;}

 

#. scss ํŒŒ์ผ์•ž์— _.scssํฌํ•จํ•˜๋Š” ์ด์œ 

  • _๊ฐ€ ์žˆ๋Š” ํŒŒ์ผ์€ ์ปดํŒŒ์ผ๋Ÿฌ ์ž‘์—… ๋ฌด์‹œ.
  • ํŒŒ์ผ๋ช…์— _๊ฐ€ ๋ถ™๋Š” ๊ฒฝ์šฐ @import ๋˜์–ด ์‚ฌ์šฉํ•  ๊ฒƒ์ž„์„ ์•”์‹œ.

  • @import ์‹œ์—๋Š” _ ๋ฅผ ๋นผ๊ณ  ๊ฒฝ๋กœ๋ฅผ ์žก์•„๋„ ์ธ์‹๋จ.

    โ”œโ”€โ”€ css
    โ”‚   โ””โ”€โ”€ common.css
    โ””โ”€โ”€ scss
    	โ”œโ”€โ”€ common.scss
    	โ”œโ”€โ”€ _reset.scss
    	โ””โ”€โ”€ _layout.scss
    
    
// common.scss
@charset "utf-8";
@import 'reset';
@import 'layout';

@import ์ˆœ์„œ๋Œ€๋กœ ์Šคํƒ€์ผ์ด ์ ์šฉ.

$ sass --watch scss:css --style compact

cssํด๋”์•ˆ์— common.cssํŒŒ์ผ๋งŒ ์ƒ์„ฑ์ด ๋œ๋‹ค.

_๊ฐ€ ๋ถ™์ธ scssํŒŒ์ผ์€ ์ปดํŒŒ์ผ๋˜์ง€ ์•Š๋Š”๋‹ค.

 

#. ๋ช…๋ น์–ด

// ์ปดํŒŒ์ผ ๋ฐฉ๋ฒ•
$ sass input.scss output.css

// compact ํ˜•์‹์œผ๋กœ ์ปดํŒŒ์ผ
$ sass --style compact input.scss out.css

// MapํŒŒ์ผ ์ œ์™ธํ•˜๊ณ  ์ปดํŒŒ์ผ
$ sass --sourcemap=none input.scss output.css

// ์ž๋™์ปดํŒŒ์ผ ๋ฐฉ๋ฒ•
$ sass --watch input.scss:output.css

// ์ž๋™์œผ๋กœ MapํŒŒ์ผ ์ œ์™ธํ•˜๊ณ  ์ปดํŒŒ์ผ
$ sass --watch --sourcemap=none input.scss:output.css

// ์ž๋™์œผ๋กœ compactํ˜•์‹์œผ๋กœ ์ปดํŒŒ์ผ
$ sass --watch --style compact input.css

// ์ž๋™์œผ๋กœ MapํŒŒ์ผ ์ œ์™ธํ•˜๊ณ  compact ํ˜•์‹์œผ๋กœ ์ปดํŒŒ์ผ
$ sass --watch --sourcemap

 


Reference

Sass - CSS Extensions

SASS ๋ณ€ํ™˜์Šคํƒ€์ผ

 

๋ฐ˜์‘ํ˜•