Skip to content

Latest commit

Β 

History

History
151 lines (106 loc) Β· 3.53 KB

File metadata and controls

151 lines (106 loc) Β· 3.53 KB
title μ„€μ •

이 νŽ˜μ΄μ§€μ—μ„œλŠ” React μ»΄νŒŒμΌλŸ¬μ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” λͺ¨λ“  μ„€μ • μ˜΅μ…˜μ„ λ‚˜μ—΄ν•©λ‹ˆλ‹€.

λŒ€λΆ€λΆ„μ˜ μ•±μ—μ„œλŠ” κΈ°λ³Έ μ˜΅μ…˜μ΄ 기본적으둜 잘 μž‘λ™ν•©λ‹ˆλ‹€. νŠΉλ³„ν•œ ν•„μš”μ„±μ΄ μžˆλŠ” κ²½μš°μ— μ΄λŸ¬ν•œ κ³ κΈ‰ μ˜΅μ…˜μ„ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

// babel.config.js
module.exports = {
  plugins: [
    [
      'babel-plugin-react-compiler', {
        // compiler options
      }
    ]
  ]
};

컴파일 μ œμ–΄ {/compilation-control/}

이 μ˜΅μ…˜λ“€μ€ μ»΄νŒŒμΌλŸ¬κ°€ 무엇을 μ΅œμ ν™”ν•˜κ³ , μ–΄λ–»κ²Œ μ»΄ν¬λ„ŒνŠΈμ™€ Hook을 컴파일 λŒ€μƒμœΌλ‘œ 선택할지λ₯Ό μ œμ–΄ν•©λ‹ˆλ‹€.

  • compilationModeλŠ” μ»΄νŒŒμΌν•  ν•¨μˆ˜λ₯Ό μ„ νƒν•˜λŠ” μ „λž΅μ„ μ œμ–΄ν•©λ‹ˆλ‹€. (예: λͺ¨λ“  ν•¨μˆ˜, μ–΄λ…Έν…Œμ΄μ…˜λœ ν•¨μˆ˜λ§Œ, λ˜λŠ” 컴파일러의 μžλ™ 감지)
{
  compilationMode: 'annotation' // "use memo"κ°€ λͺ…μ‹œλœ ν•¨μˆ˜λ§Œ μ»΄νŒŒμΌν•©λ‹ˆλ‹€.
}

버전 ν˜Έν™˜μ„± {/version-compatibility/}

React 버전 섀정은 μ»΄νŒŒμΌλŸ¬κ°€ ν˜„μž¬ μ‚¬μš© 쀑인 React 버전과 ν˜Έν™˜λ˜λŠ” μ½”λ“œλ₯Ό μƒμ„±ν•˜λ„λ‘ ν•©λ‹ˆλ‹€.

target은 ν˜„μž¬ μ‚¬μš© 쀑인 React 버전(17, 18, λ˜λŠ” 19)을 μ§€μ •ν•©λ‹ˆλ‹€.

// React 18을 μ‚¬μš©ν•˜λŠ” ν”„λ‘œμ νŠΈμ˜ 경우
{
  target: '18' // react-compiler-runtime νŒ¨ν‚€μ§€κ°€ ν•„μš”ν•©λ‹ˆλ‹€.
}

μ—λŸ¬ 처리 {/error-handling/}

이 μ˜΅μ…˜λ“€μ€ React의 κ·œμΉ™μ„ λ”°λ₯΄μ§€ μ•ŠλŠ” μ½”λ“œμ— λŒ€ν•΄ μ»΄νŒŒμΌλŸ¬κ°€ μ–΄λ–»κ²Œ λŒ€μ‘ν•˜λŠ”μ§€λ₯Ό μ œμ–΄ν•©λ‹ˆλ‹€.

panicThresholdλŠ” λΉŒλ“œλ₯Ό μ‹€νŒ¨λ‘œ μ²˜λ¦¬ν• μ§€, λ¬Έμ œκ°€ μžˆλŠ” μ»΄ν¬λ„ŒνŠΈλ₯Ό κ±΄λ„ˆλ›Έμ§€λ₯Ό κ²°μ •ν•©λ‹ˆλ‹€.

// ν”„λ‘œλ•μ…˜ ν™˜κ²½μ— ꢌμž₯
{
  panicThreshold: 'none' // λΉŒλ“œλ₯Ό μ‹€νŒ¨μ‹œν‚€λŠ” λŒ€μ‹  였λ₯˜κ°€ μžˆλŠ” μ»΄ν¬λ„ŒνŠΈλ₯Ό κ±΄λ„ˆλœλ‹ˆλ‹€.
}

디버깅 {/debugging/}

λ‘œκΉ… 및 뢄석 μ˜΅μ…˜μ€ 컴파일러의 λ™μž‘μ„ μ΄ν•΄ν•˜λŠ” 데 도움을 μ€λ‹ˆλ‹€.

loggerλŠ” 컴파일 μ΄λ²€νŠΈμ— λŒ€ν•œ μ»€μŠ€ν…€ λ‘œκΉ…μ„ μ œκ³΅ν•©λ‹ˆλ‹€.

{
  logger: {
    logEvent(filename, event) {
      if (event.kind === 'CompileSuccess') {
        console.log('Compiled:', filename);
      }
    }
  }
}

κΈ°λŠ₯ ν”Œλž˜κ·Έ {/feature-flags/}

쑰건뢀 μ»΄νŒŒμΌμ„ μ‚¬μš©ν•˜λ©΄ μ΅œμ ν™”λœ μ½”λ“œκ°€ μ–Έμ œ μ‚¬μš©λ μ§€λ₯Ό μ œμ–΄ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

gating은 A/B ν…ŒμŠ€νŠΈλ‚˜ 점진적 배포λ₯Ό μœ„ν•œ λŸ°νƒ€μž„ κΈ°λŠ₯ ν”Œλž˜κ·Έλ₯Ό ν™œμ„±ν™”ν•©λ‹ˆλ‹€.

{
  gating: {
    source: 'my-feature-flags',
    importSpecifierName: 'isCompilerEnabled'
  }
}

곡톡 μ„€μ • νŒ¨ν„΄ {/common-patterns/}

κΈ°λ³Έ μ„€μ • {/default-configuration/}

λŒ€λΆ€λΆ„μ˜ React 19 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ—μ„œλŠ” λ³„λ„μ˜ μ„€μ • 없이도 μ»΄νŒŒμΌλŸ¬κ°€ μ •μƒμ μœΌλ‘œ λ™μž‘ν•©λ‹ˆλ‹€.

// babel.config.js
module.exports = {
  plugins: [
    'babel-plugin-react-compiler'
  ]
};

React 17/18 ν”„λ‘œμ νŠΈ {/react-17-18/}

React 17/18 ν”„λ‘œμ νŠΈμ—μ„œλŠ” λŸ°νƒ€μž„ νŒ¨ν‚€μ§€μ™€ target 섀정이 ν•„μš”ν•©λ‹ˆλ‹€.

npm install react-compiler-runtime@latest
{
  target: '18' // or '17'
}

점진적 적용 {/incremental-adoption/}

νŠΉμ • 디렉토리뢀터 μ‹œμž‘ν•΄ μ μ§„μ μœΌλ‘œ ν™•μž₯ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

{
  compilationMode: 'annotation' // "use memo"κ°€ λͺ…μ‹œλœ ν•¨μˆ˜λ§Œ μ»΄νŒŒμΌν•©λ‹ˆλ‹€.
}