이 시리즈의 글은 Next.js Documentation을 번역하는 글이다.
프론트엔드 개발자로서 Next.js에 대해서는 꼭 알아둬야 할 것 같아서 공부를 시작한다.
그럼 렛츠 고우!
원본: https://nextjs.org/docs/getting-started
Next.js System Requirements
1) 'create-next-app'을 사용하여 Next.js 앱을 자동으로 생성하고 설정해줄 수 있다.
npx create-next-app@latest
# or
yarn create next-app
2) typescript를 사용하고 싶다면 '--typescript'를 추가하면 된다.
npx create-next-app@latest --typescript
# or
yarn create next-app --typescript
3) 설치 후 실행하기
'npm run dev', 'yarn dev', 'pnpm dev'를 실행하면 'https://localhost:3000' 에서 개발 서버(dev)를 실행할 수 있다. 브라우저에서 이 주소를 열면 pages/index.js의 내용이 보인다.
1) next, react, react-dom을 설치한다.
npm install next react react-dom
# or
yarn add next react react-dom
2) package.json 파일에 아래의 스크립트를 추가해준다.
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
}
3) root에 pages와 public 디렉토리를 생성한다.
Next.js는 기본적으로 page라는 개념을 기반으로 구축되었다. page란 pages 디렉토리 안의 .js, .jsx, .ts, .tsx 파일에서 export된 리액트 컴포넌트를 의미한다.
pages 내부의 index.js 파일은 앱을 처음으로 방문했을 때 렌더링되는 페이지이다.
여기까지 하면 Next.js의 기본 구성은 끝났고, 다음과 같은 기능이 제공된다.