๐Ÿš€ next.js ๋ฅผ yarn berry์™€ typescript๋กœ ์‹œ์ž‘ํ•ด๋ฒ„๋ฆฌ๊ธฐ

RECOยท2021๋…„ 12์›” 28์ผ
13
post-thumbnail

vercel์˜ nextjs๋ฅผ yarn berry๋กœ ์‹œ์ž‘ํ•ด๋ณด์ž!

1. create-nexp-app ํ•ด๋ฒ„๋ฆฌ๊ธฐ

yarn , node, npm ์„ค์น˜๊ฐ€ ๋˜์–ด์žˆ๋‹ค๋Š” ์ „์ œํ•˜์— ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ๋ช…๋ น์„ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ด๋ฒ„๋ฆฌ์ฃ .

yarn create next-app --typescript

์ธํ’‹์ฐฝ์ด ๋‚˜์˜ค๋ฉด ๊ธฐ๋Œ€ํ•˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋ช…/ํ”„๋กœ์ ํŠธ๋ช…์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.
์ „ nextjs-project ์„ ์ž…๋ ฅํ• ๊ฑฐ์—์š”!

โš ๏ธ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด, ์ƒ์œ„ ๋””๋ ‰ํ† ๋ฆฌ์— package.json์ด๋‚˜ yarn.lock์ด ์žˆ๋Š”๊ฑด ์•„๋‹Œ์ง€ ์˜์‹ฌํ•ด๋ณด์„ธ์š”. (์ „ 2์‹œ๊ฐ„ ์‚ฝ์งˆํ–ˆ์–ด์š” ๐Ÿ˜ญ )

2. ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ to yarn berry

yarn berry๋ฅผ ์“ฐ๋ฉด ์™œ ์ข‹์„๊นŒ?

zero install ์„ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ yarn berry๋ฅผ ์„ธํŒ…ํ•ฉ๋‹ˆ๋‹ค.

# ์ตœ์‹ ๋ฒ„์ „์˜ yarn(berry) ์‚ฌ์šฉ ์„ค์ •
yarn set version stable

# ํŒจํ‚ค์ง€ ์„ค์น˜
yarn

# ์œ„์—์„œ node_modules๊ฐ€ ์ƒ๊ธด๋‹ค๋ฉด ์•„๋ž˜๋ฅผ package.json์— ์ถ”๊ฐ€
"packageManager": "yarn@3.1.1",

# ์•„๋ž˜๋ฅผ ๊ทธ๋ƒฅ ์‹คํ–‰(.yarnrc.yml ์— pnp ๋‚ด์šฉ ์ถ”๊ฐ€)
echo 'nodeLinker: "pnp"' >> .yarnrc.yml

# yarn typescript ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์ •
yarn plugin import typescript
yarn add -D typescript
yarn

# ํƒ€์ž…/๋ชจ๋“ˆ ์ถ”๋ก ์„ ์œ„ํ•œ yarn berry์˜ vscode ์„ธํŒ…
yarn dlx @yarnpkg/sdks vscode

# ๊ฐœ๋ฐœ๋ชจ๋“œ๋กœ ๋„์›Œ๋ณด๊ธฐ
yarn dev

๐Ÿ‘† ์œ„์ฒ˜๋Ÿผ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด ๐Ÿ‘‡ ์•„๋ž˜๋ฅผ ๋ด์ฃผ์„ธ์š”.

3. vercel/nextjs yarn 2 pnp support

vercel/next.js๊ฐ€ yarn berry๋ฅผ ๋งค๋„๋Ÿฝ๊ฒŒ ์ง€์›ํ•ด์ฃผ์ง€๋Š” ์•Š๋Š” ๋“ฏ ํ•œ๋ฐ, ์ตœ์‹  ๋ฒ„์ „์—์„œ๋Š” patch๋˜์–ด ์ •์ƒ ๋™์ž‘์ด ๋˜๋Š” ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค.

์ฐพ์•„๋ณธ ๊ธฐ๋ก ๐Ÿ‘‡
https://github.com/vercel/next.js/issues/20955
https://github.com/vercel/next.js/issues/31552

ํ•œ ์ค„ ์š”์•ฝ
yarn add next@12.0.4 ๋กœ ์—…๋ฐ์ดํŠธํ•ด์ฃผ๋ฉด ํ•ด๊ฒฐ ๐Ÿ‘

4. zero install์„ ์œ„ํ•˜์—ฌ

https://yarnpkg.com/getting-started/qa/#which-files-should-be-gitignored

.gitignore์— ์•„๋ž˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋‹ค์Œ๋ถ€ํ„ฐ clone๋ฐ›์„ ๋•Œ, ๋น ๋ฅด๊ฒŒ ์„ค์น˜ ๊ฐ€๋Šฅํ•ด์š”

.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

5. github ๋งํฌ

์œ„ ์ž‘์—…๋œ ๋‚ด์šฉ์€ ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š” ๐Ÿ‘€
์˜ค์…”์„œ โญ๏ธ ๋ˆŒ๋Ÿฌ์ฃผ์‹œ๋Š” ๊ฑฐ ์žŠ์ง€ ๋งˆ์„ธ์š” ๐Ÿ˜

profile
frontend engineer

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 9์›” 3์ผ

์ด์ œ ์ฒ˜์Œ Next.js๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ์‹œ์ž‘ํ–ˆ๋Š”๋ฐ, ๊น”๋”ํ•œ ์ •๋ฆฌ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ˜„

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ