๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป DEV/NextJS

[Nextjs] ์ดˆ๊ธฐ ์„ค์น˜ & ์„ธํŒ… (Installation)

by Rising Oneโ˜… 2023. 6. 1.
728x90
๋ฐ˜์‘ํ˜•
SMALL

NextJS ๋Œ€ํ‘œ๋กœ๊ณ 


์ ‘๊ทผ (์š”์•ฝ)

 

  1. Automatic Installation_NextJS app ๋งŒ๋“ค๊ธฐ

      (1.1) create-next-app ๋ช…๋ น์–ด ์‚ฌ์šฉ

 

  2. Manual Installation_ํ•„์ˆ˜ ํŒจํ‚ค์ง€ ์„ค์น˜

      (2.1). npm install (next@latest / react@latest / react-dom@latest)

      (2.2). package.json ํŒŒ์ผ ์—ด๊ณ  scripts ์ถ”๊ฐ€ํ•˜๊ธฐ

      (2.3). scripts ์ƒ์„ธ๋‚ด์šฉ ์ •๋ฆฌ

 

  3. ํ”„๋กœ์ ํŠธ ๋‚ด, app ํด๋” ์ƒ์„ฑํ•˜๊ธฐ

      (3.1). app/layout.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

      (3.2). app/page.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

 

  4. (optional) ํ”„๋กœ์ ํŠธ ๋‚ด, public ํด๋” ์ƒ์„ฑํ•˜๊ธฐ

      (4.1). app/layout.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

      (4.2). app/page.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

 

  5. Development Server ์‹คํ–‰(Run)

      (5.1). npm run dev ๋ช…๋ น์–ด ์‚ฌ์šฉ

      (5.2). http://localhost:3000 ์ ‘์†

      (5.3). app/layout.tsx / app/page.tsx ์ˆ˜์ •ํ•ด๋ณด๊ธฐ

 

 


๋ฐฉ๋ฒ•

  1. Automatic Installation_NextJS app ๋งŒ๋“ค๊ธฐ

      (1.1) create-next-app ๋ช…๋ น์–ด ์‚ฌ์šฉ

npx create-next-app@latest ๋ช…๋ น์–ด

'npx create-next-app'์ด๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Next.js app ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ sets up๋“ค์€ ์ž๋™์œผ๋กœ ๊ตฌ์„ฑ์ด ๋ฉ๋‹ˆ๋‹ค. 

(npx create-next-app ๋’ค์— ๋ถ™์€ '@latest'๋Š” ๊ฐ€์žฅ ์ตœ์‹ ์˜ ๋ฒ„์ „์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.)

ํ”„๋กœ์ ํŠธ sets up์„ ์ž๋™ ์™„๋ฃŒํ•˜๊ธฐ ์ „, ์„ค์ •๊ฐ’์„ ์œ ์ €์—๊ฒŒ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•จ.

Next.js app์˜ ๋ช…์นญ์„ ์ž‘์„ฑํ•ด์คŒ์œผ๋กœ ์‹œ์ž‘ํ•ด,

Next.js app์— ๊ธฐ๋ณธ์œผ๋กœ ๊ตฌ์„ฑ์ด ๋˜์–ด์žˆ๋Š” TypeScript, ESLint, Tailwind CSS๋ฅผ ๊ตฌ์„ฑํ• ์ง€ ๋ฌป๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

Next13์ด์ „์— ์‚ฌ์šฉํ–ˆ๋˜ "src/"๋ฅผ ์„ ํƒํ• ์ง€, Next13์ดํ›„์— ์‚ฌ์šฉ๋  App Router๋ฅผ ์„ ํƒํ• ์ง€ ๊ฒฐ์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 

NextJS project ์ƒ์„ฑ ํ›„ Explorer ๋ชจ์Šต

๊ทธ๋ ‡๊ฒŒ, NextJS ํ”„๋กœ์ ํŠธ app์„ ๊ตฌ์„ฑ(์ƒ์„ฑ)ํ•˜๊ณ  ๋‚˜๋ฉด, ์œ„์™€๊ฐ™์ด ์ž๋™์œผ๋กœ ๊ตฌ์„ฑ๋œ sets up ๋‚ด์—ญ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.


  2. Manual Installation_ํ•„์ˆ˜ ํŒจํ‚ค์ง€ ์„ค์น˜

      (2.1). npm install (next@latest / react@latest / react-dom@latest)

ํ•„์ˆ˜ ํŒจํ‚ค์ง€ (Required packages)์ธ next / react  / react-dom์„ ์„ค์น˜

      (2.2). package.json ํŒŒ์ผ ์—ด๊ณ  scripts ์ถ”๊ฐ€ํ•˜๊ธฐ

package.json ํŒŒ์ผ ๋‚ด scripts ๋‚ด์šฉ ์ถ”๊ฐ€

 

 

      (2.3). scripts ์ƒ์„ธ๋‚ด์šฉ ์ •๋ฆฌ

               - dev : next dev ๋Š” Next.js๋ฅผ ๊ฐœ๋ฐœ๋ชจ๋“œ์—์„œ ์‹คํ–‰(Run)์‹œํ‚ค๋Š” ๊ฒƒ

               - build : next build๋Š” ๋ฐฐํฌ ์‚ฌ์šฉ์„ ์œ„ํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋นŒ๋“œ(build)์‹œํ‚ค๋Š” ๊ฒƒ

               - start : next start๋Š” Next.js ๋ฐฐํฌ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๊ฒƒ

               - lint : Next.js๊ฐ€ ๋‚ด์žฅํ•˜๊ณ  ์žˆ๋Š” ESLint ๊ตฌ์„ฑ์„ set up ์‹œํ‚ค๋Š” ๊ฒƒ


  3. ํ”„๋กœ์ ํŠธ ๋‚ด, app ํด๋” ์ƒ์„ฑํ•˜๊ธฐ

      (3.1). app/layout.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

      (3.2). app/page.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

 

 

 


  4. (optional) ํ”„๋กœ์ ํŠธ ๋‚ด, public ํด๋” ์ƒ์„ฑํ•˜๊ธฐ

      (4.1). app/layout.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

      (4.2). app/page.tsx ๋‚ด์— ์ฝ”๋“œ ์ถ”๊ฐ€

 

 

 


  5. Development Server ์‹คํ–‰(Run)

      (5.1). npm run dev ๋ช…๋ น์–ด ์‚ฌ์šฉ

      (5.2). http://localhost:3000 ์ ‘์†

      (5.3). app/layout.tsx / app/page.tsx ์ˆ˜์ •ํ•ด๋ณด๊ธฐ

์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ ๋ช…์œผ๋กœ์˜ ๊ฒฝ๋กœ(path) ์ง„์ž… ํ›„,  'npm run dev' ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์ค๋‹ˆ๋‹ค.

์ดํ›„, ๊ธฐ๋ณธ url๋กœ ํ•˜๋Š” http://localhost:3000 ์— ์ ‘์†ํ•ด ํ”„๋กœ์ ํŠธ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๊ตฌ๋™์ด ๋˜๋Š”์ง€ ํ™•์ธ์„ ํ•ฉ๋‹ˆ๋‹ค.

๋งˆ์ง€๋ง‰์œผ๋กœ layout.tsx์™€ page.tsx๋ฅผ ์ˆ˜์ •ํ•ด ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์ ์šฉ์ด ๋˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

 

 

 

 

 


์ด์ƒ์œผ๋กœ, NextJS๋ฅผ ํ™œ์šฉํ•ด app ์ดˆ๊ธฐ์„ธํŒ…๊ณผ ์„ค์ •์ž‘์—…์„ ํ•™์Šตํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€ ์งˆ๋ฌธ์„ ๋Œ“๊ธ€์„ ๋‹ฌ์•„์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค^^

์˜ค๋Š˜๋„ ํŒŒ์ดํŒ…์ž…๋‹ˆ๋‹ค! 

728x90
๋ฐ˜์‘ํ˜•
LIST

๋Œ“๊ธ€