Emotion vs SCSS vs Styled-components
728x90

Today, What I learned?

ํŒ€ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉฐ ๊ฐ์ž ๊ธฐ์ˆ  ์Šคํƒ์„ ํ•˜๋‚˜์”ฉ ๋งก์•„์„œ ์–ด๋–ค ์Šคํƒ์„ ์„ ํƒํ•˜๋ฉด ์ข‹์„์ง€ ๊ณ ๋ฏผํ•ด ๋ณด๋Š” ๊ธ€์„ ์ž‘์„ฑํ•ด ๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค.

๋‚˜๋Š” ์Šคํƒ€์ผ๋ง๊ณผ ๊ด€๋ จํ•˜์—ฌ Emotion, Styled-Component, SCSS๋ฅผ ๋น„๊ตํ•ด ๋ณด์•˜๋Š”๋ฐ ์ข€ ๋‹ค๋“ฌ์–ด์„œ ์˜ฌ๋ ค๋ณธ๋‹ค.

๐ŸฅŠ Emotion vs Styled-components

๐Ÿ“ ๊ธฐ๋Šฅ ๋น„๊ต

์ „๋ฐ˜์ ์œผ๋กœ ๋‘ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๊ธฐ๋Šฅ์€ ๊ฑฐ์˜ ๋น„์Šทํ•˜๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์ฐธ๊ณ : https://github.com/jsjoeio/styled-components-vs-emotion

 

GitHub - jsjoeio/styled-components-vs-emotion: a short doc comparing the popular CSS-in-JS libraries styled-components and emoti

a short doc comparing the popular CSS-in-JS libraries styled-components and emotion - GitHub - jsjoeio/styled-components-vs-emotion: a short doc comparing the popular CSS-in-JS libraries styled-com...

github.com

 

 

 

 

๐Ÿ“ ์‚ฌ์šฉ ํŠธ๋ Œ๋“œ

emotion์€ v10์—์„œ v11๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ ๋˜๋ฉฐ @emotion/core์—์„œ @emotion/react๋กœ ํŒจํ‚ค์ง€ ์ด๋ฆ„์ด ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค.

์•„์ง v10์„ ์ด์šฉํ•˜๋Š” ๊ฐœ๋ฐœ์ž๋“ค์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‘ ํŒจํ‚ค์ง€๋ฅผ ํฌํ•จํ•˜์—ฌ Styled-components์™€์˜ ์ตœ๊ทผ ์‚ฌ์šฉ ํŠธ๋ Œ๋“œ๋ฅผ ๋น„๊ตํ•ด ๋ณด์•˜๋‹ค.

https://npmtrends.com/@emotion/core-vs-@emotion/react-vs-styled-components

์ตœ๊ทผ styled-components์˜ ์‚ฌ์šฉ๋Ÿ‰์ด ๊ธ‰๊ฒฉํžˆ ๋Š˜์—ˆ์ง€๋งŒ emotion์˜ ๋‘ ํŒจํ‚ค์ง€ ์‚ฌ์šฉ๋Ÿ‰์„ ๋”ํ–ˆ์„ ๋•Œ, emotion์ด ๋‹ค์šด๋กœ๋“œ ์ˆ˜๊ฐ€ ์ข€ ๋” ๋†’๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค!

 

 

๐Ÿ“ ๋ฒˆ๋“ค ์‚ฌ์ด์ฆˆ์™€ ํŒจํ‚ค์ง€ ์˜์กด์„ฑ

๊ทน๋ช…ํ•œ ์ฐจ์ด๋Š” ์—†์ง€๋งŒ emotion์— ๋น„ํ•ด styled-components๊ฐ€ ์‚ฌ์ด์ฆˆ๊ฐ€ ์ข€ ๋” ํฌ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

ํŒจํ‚ค์ง€ ์˜์กด์„ฑ ๋˜ํ•œ styled-components๊ฐ€ 10๊ฐœ, emtion์€ 8๊ฐœ๋กœ ์•ฝ๊ฐ„์˜ ์ฐจ์ด๊ฐ€ ๋‚œ๋‹ค.

 

 

๐Ÿ“ ํผํฌ๋จผ์Šค ์ฐจ์ด

์ฐธ๊ณ  ์ž๋ฃŒ์— ๋”ฐ๋ผ ์—Ž์น˜๋ฝ๋’ค์น˜๋ฝํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์ง€๋งŒ ์œ ์˜๋ฏธํ•  ์ •๋„๋กœ ํฌ๊ฒŒ ํผํฌ๋จผ์Šค์˜ ์ฐจ์ด๊ฐ€ ๋‚˜์ง€๋Š” ์•Š๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

https://medium.com/styled-components/announcing-styled-components-v5-beast-mode-389747abd987
https://stitches.dev/docs/benchmarks

 

 

๐Ÿ“styled-components์™€ ๋น„๊ตํ•˜์—ฌ emotion ๋งŒ์˜ ์ฐจ๋ณ„์ 

๊ทธ๊ฐ„์˜ ํ”„๋กœ์ ํŠธ์—์„œ styled-components๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•ด ๋ณด์•˜๊ธฐ์— emotion ๋งŒ์˜ ํŠน์ง•์„ ์ •๋ฆฌํ•ด ๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

  1. ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค๋ณด๋‹ค ์ข€ ๋” ๊ฐœ๋ฐœ์ž ์นœํ™”์ ์ž„
  2. styled-components๋ณด๋‹ค ๋” ์ž‘์€ ์šฉ๋Ÿ‰๊ณผ ์œ ์—ฐํ•จ
  3. css props๋กœ ์˜์กดํ•˜๊ธฐ ๋•Œ๋ฌธ์— styled-components๋ณด๋‹ค ๋„ค์ด๋ฐ์ด ๊ฐ„๋‹จํ•จ
  4. ๊ฐ์ฒด ์Šคํƒ€์ผ์„ ์‰ฝ๊ฒŒ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ์Œ
  5. SSR์—์„œ ServerStyleSheet ๋ฅผ ์„ค์ •ํ•ด์•ผ ํ•˜๋Š” styled-components์™€ ๋‹ค๋ฅด๊ฒŒ ๋ณ„๋„์˜ ์„ค์ • ํ•„์š” ์—†์Œ

 

 

SCSS

๐Ÿค” ์ž ๊น! Sass์™€ SCSS์˜ ์ฐจ์ด??

๋‘˜ ๋‹ค CSS ์ „์ฒ˜๋ฆฌ๊ธฐ๋ผ๋Š” ๊ณตํ†ต์ ์ด ์žˆ์ง€๋งŒ SCSS๋Š” Sass์—์„œ ํŒŒ์ƒ๋œ ์–ธ์–ด์ด๊ณ , ๊ฑฐ์˜ ๋™์ผํ•œ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ๋ฌธ๋ฒ•์ ์œผ๋กœ ์ฐจ์ด๊ฐ€ ์กฐ๊ธˆ ์žˆ๋‹ค๋Š” ์ !

  //Sass ⇒ ์„ธ๋ฏธ์ฝœ๋ก  ์ƒ๋žต, indent๋กœ ๊ตฌ๋ถ„.
  .text
    font-size: 20px
    a
      color: #ffffff
// SCSS ⇒ ๊ธฐ์กด์˜ CSS์™€ ๊ฑฐ์˜ ์œ ์‚ฌํ•จ. ์ค‘๊ด„ํ˜ธ+์„ธ๋ฏธ์ฝœ๋ก 
.text{
  font-size: 20px;
  a{
    color: #ffffff:
  }
}

SCSS๊ฐ€ CSS์™€ ์ข€ ๋” ์œ ์‚ฌํ•œ ๋ฌธ๋ฒ•์„ ๊ฐ–๊ณ  ์žˆ๊ณ  ํ˜ธํ™˜์„ฑ์ด ๋†’์•„ ์„ ํ˜ธ๋„๊ฐ€ ๋†’์€ ํŽธ์ด๋‹ค.
(Sass ๊ณต์‹๋ฌธ์„œ์˜ ์ €์ž๋„ SCSS๋ฅผ ์ข€ ๋” ์„ ํ˜ธํ•œ๋‹ค๊ณ ..) [https://sass-guidelin.es/ko/]

 

 

SCSS์˜ ํŠน์ง•

  • CSS ์ „์ฒ˜๋ฆฌ๊ธฐ(CSS preprocessor) : CSS์˜ ๋ฌธ์ œ์ ์„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ฐœ๋…(๋ณ€์ˆ˜, ํ•จ์ˆ˜, ์—ฐ์‚ฐ์ž, ์ƒ์† ๋“ฑ)์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ณด์™„ํ•จ
  • ๊ณตํ†ต ์š”์†Œ๋ฅผ ๋ณ€์ˆ˜์ฒ˜๋ฆฌ ํ•˜๊ฑฐ๋‚˜ ๋ฐ˜๋ณต์ ์ธ ๋ถ€๋ถ„์„ ํ•จ์ˆ˜๋กœ ๋Œ€์ฒดํ•˜์—ฌ ์žฌ์‚ฌ์šฉ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ์Œ
  • ์„ ํƒ์ž์˜ ์ค‘์ฒฉ(nesting), ์ƒ์†์œผ๋กœ ๊ตฌ์กฐํ™”๋œ ์ฝ”๋“œ๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์Œ
  • ์กฐ๊ฑด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด์„œ ๋™์ ์œผ๋กœ CSS ๊ด€๋ฆฌ ๊ฐ€๋Šฅ
  • ์ „์ฒ˜๋ฆฌ๊ธฐ์ด๊ธฐ ๋•Œ๋ฌธ์— CSS๋กœ์˜ ์ปดํŒŒ์ผ ๋„๊ตฌ๊ฐ€ ํ•„์š”ํ•จ. (.scss → .css)
  • ์ปดํŒŒ์ผ ์†Œ์š”์‹œ๊ฐ„ ํ•„์š”ํ•จ

์•„๋ž˜๋Š” ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ์— ์ผ๋˜ SCSS ์ฝ”๋“œ ์ผ๋ถ€์ธ๋ฐ, ์ด๋Ÿฐ ์‹์œผ๋กœ ์“ด๋‹ค๋Š” ์ฐธ๊ณ ๋ฅผ ์œ„ํ•ด ๊ฐ€์ ธ์™€๋ดค๋‹ค.

.guide-wrapper {  
...  
padding: 3rem 4rem 2rem;  
background-color: $color-white;  
transform: translate3d(100%, 0, 0);  
transition: transform 500ms ease-in-out;

&.is-active {  
display: block;  
transform: translate3d(0, 0, 0);  
}

.guide {  
&-header {  
@include flexbox(between, start);
  .btn-close {
    width: 32px;
    height: 32px;
    padding-bottom: 0.4rem;

    .ic-close {
      font-size: 3rem;
      color: $color-gray-400;
    }
  }
}

&-title {
  @include text-style(18);
  margin-bottom: 4rem;
  font-size: 24px;
  color: $color-gray-700;
}
...  
}  
}

 

 

 

๐ŸฅŠ SCSS vs CSS-in-JS

๐Ÿ“ ์‚ฌ์šฉ ํŠธ๋ Œ๋“œ

์‚ฌ์šฉ์ž๋Š” css-in-js์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ๋ชจ๋‘ ํ•ฉ์ณค์„ ๋•Œ, Sass์— ๋น„ํ•ด ์‚ฌ์šฉ๋Ÿ‰์ด ์ข€ ๋” ๋†’๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

 

๐Ÿ“css-in-css vs css-in-js

๋‘ ์Šคํƒ์„ ๋น„๊ตํ•ด ๋ณด๋ ค๋ฉด ๊ฒฐ๊ตญ css-in-css์™€ css-in-js์˜ ์ฐจ์ด์— ๋Œ€ํ•ด์„œ ๋ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์€๋ฐ, ๊ฐ„๋žตํ•˜๊ฒŒ ๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

css-in-css

  • CSS Module, CSS ์ „์ฒ˜๋ฆฌ๊ธฐ(Sass, Less ๋“ฑ)
  • ๋ณ„๋„์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ „ํ™˜์ด ํ•„์š” ์—†์–ด ๋น ๋ฅธ ์†๋„

css-in-js

  • Styled-components, emotion ๋“ฑ๋“ฑ์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ css๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ์‹
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์™€ CSS ์‚ฌ์ด์˜ ๋ณ€์ˆ˜๋ฅผ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ์Œ
  • ํ˜„์žฌ ์‚ฌ์šฉ ์ค‘์ธ ์Šคํƒ€์ผ๋งŒ DOM์— ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Œ
  • CSS-in-CSS์— ๋น„ํ•ด ๋Š๋ฆฐ ์†๋„ (JS→CSS๋กœ์˜ ๋ณ€ํ™˜ ํ•„์š”)
  • ๋ณ„๋„์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜๊ฐ€ ํ•„์š”ํ•˜์—ฌ ๋ฒˆ๋“ค ํฌ๊ธฐ ์ฆ๊ฐ€

์ด๊ฑด Korean FE Article ํŒ€์˜ ๋ฒˆ์—ญ๊ธ€์ธ๋ฐ ์ฝ์–ด๋ณผ ๋งŒํ•œ ์ข‹์€ ์•„ํ‹ฐํด ๊ฐ™์•„ ๋งํฌ๋ฅผ ์ฒจ๋ถ€ํ•ด ๋ณธ๋‹ค.

(๋ฒˆ์—ญ) ์šฐ๋ฆฌ๊ฐ€ CSS-in-JS์™€ ํ—ค์–ด์ง€๋Š” ์ด์œ 

 

(๋ฒˆ์—ญ) ์šฐ๋ฆฌ๊ฐ€ CSS-in-JS์™€ ํ—ค์–ด์ง€๋Š” ์ด์œ 

์›๋ฌธ: https://dev.to/srmagura/why-were-breaking-up-wiht-css-in-js-4g9b

junghan92.medium.com

 

 

๐Ÿ‘€ ์ •๋ฆฌ

CSS ์Šคํƒ€์ผ๋ง ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์–ด๋Š ์ชฝ์ด ๋” ์ข‹์œผ๋ƒ? ๋Š” ์•„์ง๊นŒ์ง€๋„ ์˜๊ฒฌ์ด ๋ถ„๋ถ„ํ•œ ๋งŒํผ ๊ฐ๊ฐ์˜ ์žฅ๋‹จ์ ์ด ์žˆ๊ณ  ์„œ๋น„์Šค ํ™˜๊ฒฝ์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ์‰ฝ๊ฒŒ ์–ด๋Š ์ชฝ์ด ๋” ์ข‹๋‹ค!..๋ผ๊ณ  ๋ฐ”๋กœ ๊ฒฐ์ •์ง“๊ธฐ๋Š” ์–ด๋ ต๋‹ค. ๋‹ค๋งŒ ์ด๋ฒˆ์— ์•Œ์•„๋ณด๋ฉฐ ์—ฌ๋Ÿฌ ์ž๋ฃŒ์™€ ๊ธ€๋“ค์„ ์ฝ์–ด๋ณธ ๊ฒฐ๊ณผ ๋Œ€์ฒด๋กœ ์ด๋Ÿฐ ์˜๊ฒฌ๋“ค์„ ๋ณผ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

  • ๊ฐœ๋ฐœ์˜ ํšจ์œจ์„ฑ์ด ์ค‘์š”ํ•˜๊ณ  ์ปดํฌ๋„ŒํŠธ ์œ„์ฃผ์˜ ํ”„๋กœ์ ํŠธ๋ผ๋ฉด? → CSS-in-JS
  • ๋ Œ๋”๋ง ์†๋„๊ฐ€ ๋นจ๋ผ์•ผ ํ•˜๋Š” ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒํ•œ ํ”„๋กœ์ ํŠธ๋ผ๋ฉด? → CSS-in-CSS
728x90