tailwind.config.js, postcss.config.js 둘 다 작성해야 함Globals.css@tailwind base;
@tailwind components;
@tailwind utilities;
tailwind.config.ts 생성Globals.css@import "tailwindcss";
app/fonts 안에 두는 방식 추천src/
└─ app/
├─ layout.tsx
└─ fonts/
└─ pretendard/
├─ Pretendard-Regular.woff2
├─ Pretendard-Medium.woff2
├─ Pretendard-SemiBold.woff2
└─ Pretendard-Bold.woff2
왜 public/fonts가 아니라 app/fonts일까?
- public/은 정적 파일이 그대로 /fonts/...로 노출됨
- app/fonts/는 next/font/local로 번들에 포함
→ 빌드 시 /_next/static/media/... 해시 경로로 최적화- 즉, app/fonts가 보안/캐싱/최적화에 유리
next/font/local을 이용해 Pretendard를 불러옴// src/app/layout.tsx
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
const pretendard = localFont({
src: [
{ path: "./fonts/pretendard/Pretendard-Regular.woff2", weight: "400", style: "normal" },
{ path: "./fonts/pretendard/Pretendard-Medium.woff2", weight: "500", style: "normal" },
{ path: "./fonts/pretendard/Pretendard-SemiBold.woff2", weight: "600", style: "normal" },
{ path: "./fonts/pretendard/Pretendard-Bold.woff2", weight: "700", style: "normal" },
],
variable: "--font-pretendard",
display: "swap", // FOUT 방지
});
export const metadata: Metadata = {
title: "My App",
description: "Generated by Next.js",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="ko" className={pretendard.variable}>
<body className="font-sans">{children}</body>
</html>
);
}
tailwind.config.js가 아니라 globals.css의 @theme에서 토큰을 관리layout.tsx의 className="font-sans"를 사용하면 자동으로 Pretendard가 적용/* globals.css */
@import "tailwindcss";
@theme {
--font-sans: var(--font-pretendard), ui-sans-serif, system-ui, -apple-system,
"Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", "Helvetica Neue",
Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
rm -rf .next
npm run dev