| title | μ€μ |
|---|
μ΄ νμ΄μ§μμλ React μ»΄νμΌλ¬μμ μ¬μ©ν μ μλ λͺ¨λ μ€μ μ΅μ μ λμ΄ν©λλ€.
λλΆλΆμ μ±μμλ κΈ°λ³Έ μ΅μ μ΄ κΈ°λ³Έμ μΌλ‘ μ μλν©λλ€. νΉλ³ν νμμ±μ΄ μλ κ²½μ°μ μ΄λ¬ν κ³ κΈ μ΅μ μ μ¬μ©ν μ μμ΅λλ€.
// babel.config.js
module.exports = {
plugins: [
[
'babel-plugin-react-compiler', {
// compiler options
}
]
]
};μ΄ μ΅μ λ€μ μ»΄νμΌλ¬κ° 무μμ μ΅μ ννκ³ , μ΄λ»κ² μ»΄ν¬λνΈμ Hookμ μ»΄νμΌ λμμΌλ‘ μ νν μ§λ₯Ό μ μ΄ν©λλ€.
compilationModeλ μ»΄νμΌν ν¨μλ₯Ό μ ννλ μ λ΅μ μ μ΄ν©λλ€. (μ: λͺ¨λ ν¨μ, μ΄λ Έν μ΄μ λ ν¨μλ§, λλ μ»΄νμΌλ¬μ μλ κ°μ§)
{
compilationMode: 'annotation' // "use memo"κ° λͺ
μλ ν¨μλ§ μ»΄νμΌν©λλ€.
}React λ²μ μ€μ μ μ»΄νμΌλ¬κ° νμ¬ μ¬μ© μ€μΈ React λ²μ κ³Ό νΈνλλ μ½λλ₯Ό μμ±νλλ‘ ν©λλ€.
targetμ νμ¬ μ¬μ© μ€μΈ React λ²μ (17, 18, λλ 19)μ μ§μ ν©λλ€.
// React 18μ μ¬μ©νλ νλ‘μ νΈμ κ²½μ°
{
target: '18' // react-compiler-runtime ν¨ν€μ§κ° νμν©λλ€.
}μ΄ μ΅μ λ€μ Reactμ κ·μΉμ λ°λ₯΄μ§ μλ μ½λμ λν΄ μ»΄νμΌλ¬κ° μ΄λ»κ² λμνλμ§λ₯Ό μ μ΄ν©λλ€.
panicThresholdλ λΉλλ₯Ό μ€ν¨λ‘ μ²λ¦¬ν μ§, λ¬Έμ κ° μλ μ»΄ν¬λνΈλ₯Ό 건λλΈμ§λ₯Ό κ²°μ ν©λλ€.
// νλ‘λμ
νκ²½μ κΆμ₯
{
panicThreshold: 'none' // λΉλλ₯Ό μ€ν¨μν€λ λμ μ€λ₯κ° μλ μ»΄ν¬λνΈλ₯Ό 건λλλλ€.
}λ‘κΉ λ° λΆμ μ΅μ μ μ»΄νμΌλ¬μ λμμ μ΄ν΄νλ λ° λμμ μ€λλ€.
loggerλ μ»΄νμΌ μ΄λ²€νΈμ λν 컀μ€ν
λ‘κΉ
μ μ 곡ν©λλ€.
{
logger: {
logEvent(filename, event) {
if (event.kind === 'CompileSuccess') {
console.log('Compiled:', filename);
}
}
}
}μ‘°κ±΄λΆ μ»΄νμΌμ μ¬μ©νλ©΄ μ΅μ νλ μ½λκ° μΈμ μ¬μ©λ μ§λ₯Ό μ μ΄ν μ μμ΅λλ€.
gatingμ A/B ν
μ€νΈλ μ μ§μ λ°°ν¬λ₯Ό μν λ°νμ κΈ°λ₯ νλκ·Έλ₯Ό νμ±νν©λλ€.
{
gating: {
source: 'my-feature-flags',
importSpecifierName: 'isCompilerEnabled'
}
}λλΆλΆμ React 19 μ ν리μΌμ΄μ μμλ λ³λμ μ€μ μμ΄λ μ»΄νμΌλ¬κ° μ μμ μΌλ‘ λμν©λλ€.
// babel.config.js
module.exports = {
plugins: [
'babel-plugin-react-compiler'
]
};React 17/18 νλ‘μ νΈμμλ λ°νμ ν¨ν€μ§μ target μ€μ μ΄ νμν©λλ€.
npm install react-compiler-runtime@latest{
target: '18' // or '17'
}νΉμ λλ ν 리λΆν° μμν΄ μ μ§μ μΌλ‘ νμ₯ν μ μμ΅λλ€.
{
compilationMode: 'annotation' // "use memo"κ° λͺ
μλ ν¨μλ§ μ»΄νμΌν©λλ€.
}