์žฌ๋ฐŒ๊ฒŒ ํ•ฉ์‹œ๋‹ค

๊ธฐ๋กํ•˜๊ธฐ, ๊ฐ€์‹œํ™”ํ•˜๊ธฐ

React

Yarn Berry๋กœ React Native ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ

์€๋˜๋”” 2022. 10. 12. 01:30

Yarn Berry๋กœ React Native ํ”„๋กœ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•ด๋ณด์ž.

https://dev-yakuza.posstree.com/ko/react-native/install-on-mac/

 

๋งฅ(Mac)์— react native ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ•ํ•˜๊ธฐ

react-native๋กœ ์•ฑ์„ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•ด ๋งฅ(Mac)์— ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•ด ๋ณด๊ณ , react-native๋กœ ์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ๊ฐ€ ์ž˜ ๋™์ž‘ํ•˜๋Š”์ง€ ํ™•์ธํ•ด ๋ด…๋‹ˆ๋‹ค.

dev-yakuza.posstree.com

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„ ๊ธ€์„ ์ฐธ๊ณ ํ–ˆ๋‹ค. Yarn Berry๋ผ๋Š” ํŠน์ˆ˜์„ฑ์ด ๋”ํ•ด์กŒ์„ ๋ฟ์ด๋‹ค.. ๐Ÿซ

 

๐Ÿซ Yarn Berry ๊ฐ„๋žตํ•˜๊ฒŒ ์ดํ•ดํ•˜๊ธฐ

  • Yarn 2.0 ์ดํ›„๋ถ€ํ„ฐ Yarn Berry๋ผ๊ณ  ์ง€์นญํ•œ๋‹ค.
  • Plug'N'Play(PnP) ๋ผ๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • node_modules ํด๋” ๋Œ€์‹  .yarn/cache ํด๋”์™€ .pnp.cjs๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  • ๋‚ด ํ”„๋กœ์ ํŠธ๊ฐ€ Yarn Berry๋กœ ๊ด€๋ฆฌ๋˜๊ณ  ์žˆ๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, .yarn/cache ํด๋”๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค. ๊ทธ ์•ˆ์— ์˜์กด์„ฑ๋“ค์ด zip ํ˜•์‹์œผ๋กœ ์ €์žฅ๋˜์–ด ์žˆ๋‹ค.

 

โŒ Yarn Berry PnP๊ฐ€ React Native์™€ ํ˜ธํ™˜๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ

 

Yarn ๊ณต์‹ ์‚ฌ์ดํŠธ์˜ Compatibility Table์„ ํ™•์ธํ•ด๋ณด๋ฉด, React Native๋Š” PnP ๋ฐฉ์‹๊ณผ ํ˜ธํ™˜์ด ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ node_modules ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค๊ณ  ๋ช…์‹œ๋˜์–ด ์žˆ๋‹ค. ์ฐธ๊ณ ๋กœ PnP ๋ฐฉ์‹๊ณผ ํ˜ธํ™˜์ด ๋˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” React Native๊ฐ€ node_modules์˜ ๊ตฌ์กฐ์— ๋งŽ์ด ์˜์กดํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

โœ… node_modules plugin ์‚ฌ์šฉํ•˜๊ธฐ

node_modules ํด๋” ๋Œ€์‹  .yarn/cache์™€ .pnp.cjs๋ฅผ ์‚ฌ์šฉํ•˜๋Š” Yarn Berry์—์„œ, ๊ธฐ์กด node_modules ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์ด๋‹ค. ์ ์šฉ ๋ฐฉ๋ฒ•์€ ๊ฐ„๋‹จํ•˜๋‹ค.

 

yarn install ์ด์ „์— ํ”„๋กœ์ ํŠธ ์ตœ์ƒ๋‹จ์— .yarnrc.yml ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค. ํŒŒ์ผ ์•ˆ์—๋Š” ๋‹ค์Œ ๋‚ด์šฉ์„ ์ž‘์„ฑํ•œ๋‹ค.

nodeLinker: node-modules

ํ•ด๋‹น ์„ค์ •์œผ๋กœ ์ธํ•ด, Yarn Berry ์ด์ „์˜ ๋ฐฉ์‹๋Œ€๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์„ค์น˜ํ•˜๊ฒŒ ๋œ๋‹ค. ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 

 

๊ฒฐ๊ณผ์ ์œผ๋กœ ๋‹ค์Œ ๋„ค ๊ฐ€์ง€๊ฐ€ ํ”„๋กœ์ ํŠธ ํด๋” ๋‚ด์— ์กด์žฌํ•œ๋‹ค.

  • .yarn/cache ํด๋”
  • node_modules ํด๋”
  • yarn.lock ํŒŒ์ผ
  • package.json ํŒŒ์ผ

 

๐Ÿคท๐Ÿป‍โ™€๏ธ Zero-Install ์€?

๋‚ด๊ฐ€ ๊ถ๊ธˆํ–ˆ๋˜ ์ ์€ node_modules ํ”Œ๋Ÿฌ๊ทธ์ธ ์‚ฌ์šฉ ์‹œ์—๋„ Zero-Install์ด ์ ์šฉ๋  ์ˆ˜ ์žˆ๋Š”์ง€์˜€๋‹ค. ์ฐธ๊ณ ๋กœ Zero-Install์ด๋ž€, Yarn Berry์—์„œ ์˜์กด์„ฑ์„ ๋ฒ„์ „ ๊ด€๋ฆฌ์— ํฌํ•จํ•˜๋Š” ๊ฒƒ์„ ๋œปํ•œ๋‹ค. ๊ฒฐ๋ก ์ ์œผ๋กœ ์ด์•ผ๊ธฐํ•˜์ž๋ฉด ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ํ•œ๋‹ค.

 

 

(๋ฒˆ์—ญํ•˜์ž๋ฉด) yarn install ์‹œ .yarn/cache๋ฅผ ์ฒดํฌํ•ด์„œ node_modules ํด๋”๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ์˜์กด์„ฑ์„ ์ƒˆ๋กœ ๋‹ค์šด ๋ฐ›๋Š” ๊ฑด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์—(there's not network fetching) ์ˆœ์ˆ˜ PnP์™€ ๋น„๊ตํ–ˆ์„ ๋•Œ ์‹œ๊ฐ„ ์ฐจ์ด๋Š” ํฌ์ง€ ์•Š๋‹ค. 

๊ทธ๋ž˜์„œ ๊ธฐ์กด๊ณผ ๋™์ผํ•˜๊ฒŒ .yarn/cache๋Š” Github์— ์˜ฌ๋ฆฌ๊ณ , node_modules๋Š” gitignore์— ์ถ”๊ฐ€ํ–ˆ๋‹ค. 

 

References

PnP compatibility table
react-native-community : yarn PnP ์ง€์› ๊ด€๋ จ issue
How to use Yarn 3 with React Native