create-next-app의 기본값은 Pages Router챗GPT의 설명은 부분적으로 정확하지만
현재(2024년 말~2025년) 상황과는 약간 다릅니다.
실제로 최신 create-next-app을 실행하면
npx create-next-app@latest my-app
대화형 프롬프트가 나타나서 직접 선택하게 됩니다.
"Would you like to use App Router? (recommended)" → Yes/No
즉,--yes 플래그를 사용하면 모든 질문에 자동으로 Yes를 선택하므로, App Router가 선택되어야 정상입니다.
첫 설치에서 App Router가 안 된 이유
더 정확한 방식
npx create-next-app@latest my-appnpx create-next-app@latest my-app \
--typescript \
--tailwind \
--app \
--src-dir
cd codeit_tailwind로 이동해도 VS Code는 여전히 부모 디렉토리를 보고 있음File → Open Folder로 codeit_tailwind 직접 열기 또는 code . 명령 사용챗GPT의 설명이 정확.
이는 많은 초보자들이 헷갈려하는 부분인데, 핵심은
VS Code의 "작업 영역(Workspace)"과
터미널의 "현재 디렉토리"는 별개!
┌─────────────────────────────────┐
│ VS Code (작업 영역: ~) │
│ │
│ 📂 탐색기 │
│ └─ codeit_tailwind/ (폴더만 보임) │
│ │
│ 📟 통합 터미널 │
│ ~/codeit_tailwind $ ← 여기는 이동됨│
└─────────────────────────────────┘
1. 프로젝트 생성
npx create-next-app@latest my-project
2. 생성 완료 후 바로 VS Code로 열기
cd my-project
code .
npx create-next-app@latest my-project && cd my-project && code .
code . 명령어가 안 될 때
macOS: Cmd + Shift + P → "Shell Command: Install 'code' command in PATH" 설치 후 터미널 재시작 필요
✅ Next.js + Tailwind 프로젝트 생성 베스트 프랙티스
1. 대화형으로 생성 (가장 명확함)
npx create-next-app@latest my-app
질문에 답하면서 설치
# - TypeScript? Yes
# - Tailwind? Yes
# - App Router? Yes (recommended)
# - src/ directory? Yes (선택사항)
2. 프로젝트 폴더로 이동하면서 VS Code 열기
cd my-app && code .
3. 개발 서버 실행
npm run dev
챗GPT의 설명은 대체로 정확했지만, 최신 create-next-app의 동작 방식(대화형 프롬프트 기본 제공)에 대한 설명이 부족했고, --yes 플래그 사용의 위험성을 충분히 강조하지 않았습니다.
tailwind.config.ts 수정하는 건 v3(구버전)이고 현재 최신은 v4이다.
빌드 후에 .next - static - 파일명 에 들어가보면 배포 전에 만들어진 애들이 들어가있음 (eg. my-element 같은 유틸리티)
<ThemeProvider>
layout
// Next.js에서 최상위 루트.
// use client 사용을 권장하지 않으므로
// use client 사용한 ThemeProvider로 한 번 감싸서 쓴다.
</ThemeProvider>
{children}이 아닌 import를 해서 쓰면 문제가 됨@variants 지시어를 활용한 다크모드, 호버 등 상태 변화 시 css 적용하기
css 파일 작성
/ globals.css /
@import "tailwindcss";
.my-element {
background: white;
@variant dark {
background: red;
}
}
my-element 클래스 적용 후 OS 다크모드 적용하기
export default function Home() {
return (
<>
<h1 className="my-element">Hello</h1>
</>
);
}
dark 모드 및 hover 시 적용되게 수정
/ globals.css /
@import "tailwindcss";
.my-element {
background: white;
@variant dark {
@variant hover {
background: red;
}
}
}
여기서 @variant는 누가 어디서 지정? hover, dark 등 키워드는 정해져있는 거라면 어디서 확인? => tailwind가 직접 지정, 공식문서에서 확인 가능
npm run build
.next/static/css/<파일명>.css 파일에서 my-element 검색 가능
이거 왜 안돼
export default function Home() {
return (
<div className="flex h-screen items-center justify-center">
<form className="w-full max-w-sm">
<div className="mb-5">
<label
htmlFor="email"
className="mb-2 block text-sm font-medium text-gray-900"
>
이메일
</label>
<input
type="email"
id="email"
className="w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900"
placeholder="abc@gmail.com"
required
/>
</div>
<div className="mb-5">
<label
htmlFor="password"
className="mb-2 block text-sm font-medium text-gray-900"
>
비밀번호
</label>
<input
type="password"
id="password"
className="w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900"
required
/>
</div>
<div className="mb-5 flex items-start">
<div className="flex h-5 items-center">
<input
id="remember"
type="checkbox"
value=""
className="h-4 w-4 rounded-sm border border-gray-300 bg-gray-50"
required
/>
</div>
<label
htmlFor="remember"
className="ml-2 text-sm font-medium text-gray-900"
>
로그인 상태 유지
</label>
</div>
<button
type="submit"
className="w-full rounded-lg bg-blue-700 px-5 py-2.5 text-center text-sm font-medium text-white"
>
Submit
</button>
</form>
</div>
);
}
여기서 한 줄에 하나 들어가도록 grid가 아닌 block사용!