[Next.js] 01. μμνκΈ°
π‘ 1. next js μμ μ μΈν
π£ Node.js λ²μ 10.13 μ΄μ μ€μΉ
Node.js μ€μΉ ν μ€μΉκ° μ μμ μΌλ‘ λμλμ§ νμΈνκΈ° μν΄μ ν°λ―Έλμ μ¬μ ν 'node -v'λ₯Ό μ λ ₯νμ¬ νμΈ.
//λ
Έλ λ²μ νμΈ
node -v
π£ npm νΉμ yarn
npm (Node Package manager)μ λ Έλ μ€μΉ μ μλμ μΌλ‘ κ°μ΄ μ€μΉκ° λ©λλ€.
// npm λ²μ νμΈ
npm -v
ν°λ―Έλμμ 'npm -v'λ₯Ό μ λ ₯νλ©΄ μ€μΉ λ²μ μ΄ λμ΅λλ€.
yarnμ νμ΄μ€λΆμμ λ§λ μλ°μ€ν¬λ¦½νΈ ν¨ν€μ§ λ§€λμ μ λλ€. npmκ³Ό κΈ°λ₯μ λμΌνκ³ , νμ΄μ€λΆ μΈ‘μμ npmλ³΄λ€ λ³΄μμ΄ λ°μ΄λκ³ μ±λ₯μ΄ λΉ λ₯΄λ€κ³ μ£Όμ₯μ νκ³ μμ΅λλ€ γ γ .. (μ¬μ€ npm, yarn λ λ€ μ’μ΅λλ€.)
yarn μ€μΉ λ°©λ²μ ν°λ―Έλμμ npm install yarn -gλΌκ³ μ λ ₯νλ©΄ λ©λλ€.
// yarn μ€μΉ
npm install yarn -g
π‘ 2. Next.js μμνκΈ°
π£ 2.1 CNAμ μ΄μ©νμ¬ μ€μΉ
npx create-next-app
or
yarn create-next-app
// typescript λ²μ
npx create-next-app --typescript
or
yarn create next-app --typescript
ν°λ―Έλμ npx create-next-appμ΄λΌκ³ μ λ ₯νλ©΄ μλμ κ°μ΄ νλ‘μ νΈ λͺ μ μ λ ₯νλ©΄, μλμΌλ‘ μ€μΉκ° μ§νλ©λλ€.
npx create-next-app
Need to install the following packages:
create-next-app
Ok to proceed? (y) y
√ What is your project named? ... my-first-next-app
Creating a new Next.js app in D:\GIT\my-first-next-app.
Using npm.
Installing dependencies:
- react
- react-dom
- next
added 16 packages, and audited 17 packages in 10s
2 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Installing devDependencies:
- eslint
- eslint-config-next
added 203 packages, and audited 220 packages in 31s
63 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Initialized a git repository.
Success! Created my-first-next-app at D:\GIT\my-first-next-app
Inside that directory, you can run several commands:
npm run dev
Starts the development server.
npm run build
Builds the app for production.
npm start
Runs the built app in production mode.
We suggest that you begin by typing:
cd my-first-next-app
npm run dev
π£ 2.2 μμ±λ Next.js νμΈνκΈ°
- node_modules ν΄λ : ν νλ‘μ νΈμ νμν λ Έλ λͺ¨λλ€μ λͺ¨μ λμ ν΄λ
- pages ν΄λ : μΉμ¬μ΄νΈμ νμ΄μ§λ€μ νμΌμ λͺ¨μ λμ ν΄λ
- public ν΄λ : next.js νλ‘μ νΈμμ μ μμ μΌλ‘ μ¬μ©νλ μ¬μ§, λμμλ€μ λͺ¨μ λμ ν΄λ
- styles ν΄λ : cssλ€μ λͺ¨μ λμ ν΄λ
- .gitignore : κΉνλΈμ μ¬λ¦΄ λ μ μΈν νλͺ©μ μ μ΄ λλ νμΌ
- next.config.js : μΉν© λ²λ€λ§ λ° api ν΅μ μ ν λ μ¬μ©
- package.json : ν νλ‘μ νΈμ μ€μ κ³Ό μ 보λ₯Ό μ μ΄ λμ νμΌ
π£ 2.3 Next.js μ€ν
1. μλν°(μ κ°μ κ²½μ°λ vscode)μμ ν°λ―Έλμ μ¬μ ν 'npm run dev'λΌκ³ μ λ ₯νλ©΄ next.jsκ° μ€νμ΄ λ©λλ€.
npm run dev
or
yarn dev
2. ν¬λ‘¬μ μ¬μ ν μ£Όμμ°½μ localhost:3000μ΄λΌκ³ μ λ ₯
π£ 2.4 next.js μ’ λ£νκΈ°
- μλν° ν°λ―Έλ ν΄λ¦ ν ctrl + c μ λ ₯, μλ μ¬μ§κ³Ό κ°μ΄ λ¬Έκ΅¬κ° λ¨λ©΄ Y μ λ ₯ ν μν°
π μ 리
- node.js μ€μΉνκΈ° (10.13 μ΄μ λ²μ μΌλ‘)
- npx create-next-app or yarn create-next-appμΌλ‘ μ€μΉ
- npm run dev or yarn devλ‘ μ€ν
κΈ΄ κΈ μ½μ΄μ£Όμ
μ κ°μ¬ν©λλ€ :)
νλ¦° λ΄μ©μ΄ μκ±°λ, λ§λΆμΌ λ΄μ©μ΄ μλ€λ©΄ μΈμ λ μ§ λκΈ λ¬μμ£ΌμΈμ!
μ κΈμ΄ μ‘°κΈμ΄λλ§ μ½μΌμ λΆλ€μκ² λμμ΄ λλλ‘ λ
Έλ ₯νκ² μ΅λλ€
λ€μ νΈμ 봬μ~
