ํฐ์คํ ๋ฆฌ ๋ทฐ
๐จ Next.js App Router์์ ์ด๋ฏธ์ง์ ํฐํธ ์ต์ ํ ์๋ฒฝ ๊ฐ์ด๋
octo54 2025. 4. 15. 11:24๐จ Next.js App Router์์ ์ด๋ฏธ์ง์ ํฐํธ ์ต์ ํ ์๋ฒฝ ๊ฐ์ด๋
Next.js๋ ํผํฌ๋จผ์ค ์ค์ฌ์ ์น ํ๋ ์์ํฌ๋ต๊ฒ, ์ด๋ฏธ์ง์ ํฐํธ ๋ฆฌ์์ค๋ฅผ ์๋์ผ๋ก ์ต์ ํํ ์ ์๋ ๊ธฐ๋ฅ์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํฉ๋๋ค.
App Router ๊ธฐ๋ฐ ํ๋ก์ ํธ์์๋ next/image
์ next/font
๋ชจ๋์ ํตํด ์์ฝ๊ฒ ๋น ๋ฅด๊ณ ๊น๋ํ UI๋ฅผ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
๐ผ๏ธ ์ด๋ฏธ์ง ์ต์ ํ: next/image
์ฌ์ฉ๋ฒ
next/image
๋ ๋ค์๊ณผ ๊ฐ์ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค:
- ์ง์ฐ ๋ก๋ฉ(Lazy Loading) ์๋ ์ฒ๋ฆฌ
- ์ด๋ฏธ์ง ํฌ๊ธฐ ์๋ ์กฐ์ ๋ฐ ๋ฆฌ์ฌ์ด์ง
- WebP ๋ฑ ์ต์ ํฌ๋งท ์๋ ๋ณํ
- ๋ ์ด์์ ์ํํธ ๋ฐฉ์ง
โ ๋ก์ปฌ ์ด๋ฏธ์ง ์ฌ์ฉ
import Image from 'next/image';
export default function Profile() {
return (
<Image
src="/profile.jpg" // public ๋๋ ํ ๋ฆฌ ๊ธฐ์ค
alt="ํ๋กํ"
width={500}
height={500}
placeholder="blur"
/>
);
}
๋๋ ์ด๋ฏธ์ง ํ์ผ์ ์ง์ importํด์ ์ฌ์ฉ:
import Image from 'next/image';
import profile from '../public/profile.jpg';
export default function Avatar() {
return <Image src={profile} alt="์๋ฐํ" />;
}
๐ ์ธ๋ถ ์ด๋ฏธ์ง(์๊ฒฉ ์ด๋ฏธ์ง) ์ฌ์ฉ
next.config.js
์ ๋๋ฉ์ธ ๋ฑ๋ก ํ์:
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'images.example.com',
},
],
},
};
์ฌ์ฉ ์์:
<Image
src="https://images.example.com/image.jpg"
alt="์๊ฒฉ ์ด๋ฏธ์ง"
width={600}
height={400}
/>
๐
ฐ๏ธ ํฐํธ ์ต์ ํ: next/font
์ฌ์ฉ๋ฒ
โ Google Fonts
๋น๋ ์ ๋ค์ด๋ก๋๋์ด ์์ฒด ํธ์คํ ๋ฐฉ์์ผ๋ก ์ ์ฉ๋๋ฏ๋ก ์ฑ๋ฅ๊ณผ ๋ณด์์ ์ ๋ฆฌํฉ๋๋ค.
// app/layout.tsx
import { Inter } from 'next/font/google';
const inter = Inter({ subsets: ['latin'] });
export default function RootLayout({ children }) {
return (
<html lang="ko" className={inter.className}>
<body>{children}</body>
</html>
);
}
โ ๋ก์ปฌ ํฐํธ
// app/fonts.ts
import localFont from 'next/font/local';
export const pretendard = localFont({
src: './fonts/Pretendard.woff2',
display: 'swap',
});
import { pretendard } from './fonts';
export default function Text() {
return <p className={pretendard.className}>๋ก์ปฌ ํฐํธ ์ ์ฉ</p>;
}
๐จ Tailwind CSS์ ํจ๊ป ์ฌ์ฉ
ํฐํธ๋ฅผ CSS ๋ณ์๋ก ์ ์ํ๊ณ Tailwind ์ค์ ์ ์ฐ๋ํฉ๋๋ค.
// app/fonts.ts
import { Inter } from 'next/font/google';
export const inter = Inter({
subsets: ['latin'],
variable: '--font-inter',
});
// tailwind.config.js
module.exports = {
theme: {
extend: {
fontFamily: {
sans: ['var(--font-inter)', 'sans-serif'],
},
},
},
};
// ์ฌ์ฉ ์์
<p className="font-sans">Tailwind๋ก ์ ์ฉ๋ ํฐํธ</p>
โ ์์ฝ ์ ๋ฆฌ
ํญ๋ชฉ | ํต์ฌ ๊ธฐ๋ฅ | ๋ชจ๋ |
---|---|---|
์ด๋ฏธ์ง ์ต์ ํ | ์ง์ฐ ๋ก๋ฉ, ์๋ ํฌ๊ธฐ ์กฐ์ , WebP ๋ณํ | next/image |
๋ก์ปฌ ์ด๋ฏธ์ง | /public/ ์์ ์ฌ์ฉ ๊ฐ๋ฅ |
import ๋๋ ๊ฒฝ๋ก ์ง์ |
์๊ฒฉ ์ด๋ฏธ์ง | ๋๋ฉ์ธ ๋ฑ๋ก ํ ์ฌ์ฉ | next.config.js |
Google Fonts ์ต์ ํ | ์์ฒด ํธ์คํ ๋ฐฉ์ | next/font/google |
๋ก์ปฌ ํฐํธ ์ ์ฉ | ํ๋ก์ ํธ ๋ด ํฐํธ ์ง์ ์ฌ์ฉ | next/font/local |
Tailwind ์ฐ๋ | CSS ๋ณ์๋ก ํฐํธ ์ ์ฉ | tailwind.config.js ์ค์ |
Next.js, App Router, ์ด๋ฏธ์ง ์ต์ ํ, ํฐํธ ์ต์ ํ, next/image, next/font, ์น ํผํฌ๋จผ์ค, Google Fonts, ๋ก์ปฌ ํฐํธ, Tailwind CSS
'framework > NextJS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
- Total
- Today
- Yesterday
- seo ์ต์ ํ 10๊ฐ
- nodejs
- rag
- SEO์ต์ ํ
- kotlin
- ๋ฐฑ์๋๊ฐ๋ฐ
- ์น๊ฐ๋ฐ
- CI/CD
- gatsbyjs
- Docker
- Next.js
- ๊ฐ๋ฐ๋ธ๋ก๊ทธ
- ์ค๋งํธ ์ปจํธ๋ํธ
- PostgreSQL
- REACT
- ํ๋ก ํธ์๋
- LangChain
- NestJS
- fastapi
- Webpack
- github
- AI ์๋ํ
- ๊ด๋ฆฌ์
- SEO ์ต์ ํ
- llm
- AI์ฑ๋ด
- nextJS
- App Router
- Prisma
- Ktor
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |