λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

πŸ‘©πŸ»‍πŸ’» dev

[Sass] 주석(Comments)

μ‹œμž‘ν•˜κΈ°μ— μ•žμ„œ

✍️ ν•΄λ‹Ή 글은 .scss λ₯Ό κΈ°μ€€μœΌλ‘œ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€!
.scss와 .sass ν™•μž₯μžμ— 따라 주석이 λ™μž‘ν•˜λŠ” λ°©μ‹μ—λŠ” 차이가 μžˆμ§€λ§Œ
κ³΅ν†΅μ μœΌλ‘œ /**/둜 μž‘μ„±λ˜λŠ” 주석은 css둜 μ»΄νŒŒμΌλœλ‹€λŠ” 점, // 둜 μž‘μ„±λœ 주석은 컴파일 λ˜μ§€ μ•ŠλŠ”λ‹€λŠ” 점은 λ™μΌν•©λ‹ˆλ‹€!

λ””μžμΈ μ‹œμŠ€ν…œμ„ λ§Œλ“€λ©΄μ„œ scss μ‚¬μš©λ„ μ΅νžˆλŠ” 쀑이닀.
μ—¬λŸ¬ μžλ£Œλ“€μ„ μ°Έκ³ ν•˜λ˜ 도쀑 주석 μŠ€νƒ€μΌμ΄ μ‘°κΈˆμ”© λ‹¬λžλ‹€.
μ–΄λ–€ κ²½μš°μ—λŠ” μ–΄λ–€ κ±Έ μ“°λŠ” 지 κΆκΈˆν•΄μ„œ 이번 ν¬μŠ€νŒ…μ—μ„œ λ‹€λ€„λ³΄κΈ°λ‘œ ν–ˆλ‹€.

Scssμ—μ„œμ˜ 주석

scssμ—μ„œ μ‚¬μš©ν•˜λŠ” 주석은 jsμ—μ„œ λ™μž‘ν•˜λŠ” 방식과 μœ μ‚¬ν•˜λ‹€.

 // λ‘œ μ‹œμž‘ν•˜λŠ” single-line comment(ν•œ 쀄 주석)듀은 cssμ—μ„œλŠ” silent comment라고도 λΆˆλ¦¬λŠ”λ°, μ–΄λ– ν•œ css도 λ§Œλ“€μ§€ μ•ŠκΈ° λ•Œλ¬Έμ΄λ‹€.

/**/둜 μ‹œμž‘ν•˜λŠ” multi-line comment(μ—¬λŸ¬ 쀄 주석)λŠ”  statementκ°€ ν—ˆλ½λ˜λŠ” 곳에 μž‘μ„±λœλ‹€λ©΄ css μ£Όμ„μœΌλ‘œ μ»΄νŒŒμΌλœλ‹€.

λ”°λΌμ„œ loud comment라고도 λΆˆλ¦°λ‹€. multi-line comment은 css둜 컴파일될 경우 interpolationλ₯Ό 포함할 μˆ˜λ„ μžˆλŠ”λ°, 이 경우 주석이 컴파일되기 전에 평가가 λœλ‹€.

 

기본적으둜 multi-line comment은  compressed modeμ—μ„œλŠ” μ»΄νŒŒμΌλ˜μ§€ μ•ŠλŠ”λ‹€.

λŒ€μ‹  /*!*/둜 μž‘μ„±ν•˜λ©΄ 무쑰건 css에 μ»΄νŒŒμΌλœλ‹€.

 

// css νŒŒμΌμ— μ—†λŠ” κ±°λž‘ λ§ˆμ°¬κ°€μ§€μΈ 주석 ν˜•νƒœ

/* compressed modeμ—μ„œλŠ” μ»΄νŒŒμΌλ˜μ§€ μ•ŠμŒ */

/* interpolation 포함 κ°€λŠ₯:
* 1 + 1 = #{1 + 1} */

/*! compressed modeμ—μ„œλ„ ν¬ν•¨λ˜λŠ” 주석 */

p /* Multi-line comments λŠ” whitespaceλ₯Ό μ‚¬μš©ν•  수 μžˆλŠ” 어디든지 μ“Έ 수 μžˆλ‹€  */ .sans {
  font: Helvetica, // single-line comment도 λ§ˆμ°¬κ°€μ§€λ‹€
        sans-serif;
}

Documentation Comments

sass 라이브러리λ₯Ό μ‚¬μš©ν•  λ•Œ λΌμ΄λΈŒλŸ¬λ¦¬κ°€ μ œκ³΅ν•˜λŠ” mixin, functions, variables 그리고 placeholder selector와 라이브러리 κ·Έ μžμ²΄μ— λŒ€ν•œ Documentation Comments(λ¬Έμ„œν™”μš© 주석)을 달 수 μžˆλ‹€. SassDocs 도ꡬλ₯Ό ν™œμš©ν•˜λ©΄ 읽기 μ‰½κ²Œ λ¬Έμ„œν™”λœ 버전을 읽을 수 μžˆλ‹€.

 

Documentation Comments은 silent comment에 ν•΄λ‹Ήλœλ‹€.

/// λ‘œ λ¬Έμ„œν™”ν•˜κ³ μžν•˜λŠ” 것 λ°”λ‘œ μœ„μ— μž‘μ„±ν•˜λ©΄ λœλ‹€. λ¬Έμ„œν™”λœ 주석듀은 λ§ˆν¬λ‹€μš΄μœΌλ‘œ νŒŒμ‹± 된고, annotation을 μ§€μ›ν•œλ‹€.

/// Computes an exponent.
///
/// @param {number} $base
///   The number to multiply by itself.
/// @param {integer (unitless)} $exponent
///   The number of `$base`s to multiply together.
/// @return {number} `$base` to the power of `$exponent`.
@function pow($base, $exponent) {
  $result: 1;
  @for $_ from 1 through $exponent {
    $result: $result * $base;
  }
  @return $result;
}

 

πŸ€” μ΄λ²ˆμ—λŠ” κ°„λ‹¨ν•˜κ²Œ scss μ—μ„œ μ£Όμ„μ˜ 차이에 λŒ€ν•΄μ„œ μ‚΄νŽ΄λ΄€λ‹€.
// 은 css 결과에 ν¬ν•¨λ˜μ§€ μ•ŠλŠ” 주석, /**/은 compressed modeκ°€ μ•„λ‹Œ 경우 컴파일되고, /*!*/λŠ” 무쑰건 μ»΄νŒŒμΌλ˜λŠ” 주석이닀.
λ‹€μŒμ—λŠ” sassdoc에 λŒ€ν•΄ 더 μ•Œμ•„λ³΄κ³  μ μš©μ„ ν•΄λ³΄μž.

πŸ“š References

https://sass-lang.com/documentation/syntax/comments/

 

Sass: Comments

The way Sass comments work differs substantially between SCSS and the indented syntax. Both syntaxes support two types of comments: comments defined using /* */ that are (usually) compiled to CSS, and comments defined using // that are not. Comments in SC

sass-lang.com