ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ชฒ Next.js ๋๋ฒ๊น ๊ฐ์ด๋
Next.js ์ ํ๋ฆฌ์ผ์ด์
์ ๊ฐ๋ฐํ๋ฉด์ ๋ฐ์ํ๋ ๋ค์ํ ๋ฌธ์ ๋ฅผ ํจ๊ณผ์ ์ผ๋ก ํด๊ฒฐํ๊ธฐ ์ํด ๋๋ฒ๊น
์ ๋ต์ ์ ๋ฆฌํ์ต๋๋ค.
React ํน์ฑ์ ํด๋ผ์ด์ธํธ์ ์๋ฒ ์ฌ์ด์์ ๋ฐ์ํ๋ ์ด์๋ฅผ ๋ชจ๋ ํฌ๊ดํ์ฌ ๋ค๋ฃน๋๋ค.
โ 1. ๊ธฐ๋ณธ ๋๋ฒ๊น ์ค์
๋ก๊ทธ๋ฅผ ํ์ฉํ ๋๋ฒ๊น
Next.js์์๋ ์๋ฒ์ ํด๋ผ์ด์ธํธ ๋ก๊ทธ๋ฅผ ๊ตฌ๋ถํ์ฌ ์ถ๋ ฅํ ์ ์์ต๋๋ค.
// ํด๋ผ์ด์ธํธ ๋ก๊ทธ
console.log("ํด๋ผ์ด์ธํธ ์ธก ๋ก๊ทธ");
// ์๋ฒ ๋ก๊ทธ
if (typeof window === "undefined") {
console.log("์๋ฒ ์ธก ๋ก๊ทธ");
}
ํ๊ฒฝ ๋ณ์ ์ค์
๋๋ฒ๊น ๋ชจ๋๋ฅผ ํ์ฑํํ๋ ค๋ฉด .env ํ์ผ์ ๋ค์ ๋ณ์๋ฅผ ์ถ๊ฐํฉ๋๋ค.
NODE_ENV=development
NEXT_PUBLIC_DEBUG=true
๊ฐ๋ฐ ํ๊ฒฝ์์ ๋๋ฒ๊ทธ ์ ๋ณด๋ฅผ ์ถ๊ฐ๋ก ์ถ๋ ฅํ ๋ ์ ์ฉํฉ๋๋ค.
โ 2. Next.js ๋๋ฒ๊น ๋๊ตฌ
Chrome DevTools
- Console: ํด๋ผ์ด์ธํธ ์ธก ์ค๋ฅ ํ์ธ
- Network: API ํธ์ถ ์ํ ์ ๊ฒ
- Performance: ํ์ด์ง ๋ก๋ฉ ์๋ ํ์ธ
- Application: ๋ก์ปฌ ์คํ ๋ฆฌ์ง, ์ธ์ ๊ด๋ฆฌ ํ์ธ
VS Code ๋๋ฒ๊ฑฐ
VS Code์ Launch Configuration์ ํ์ฉํ์ฌ ๋๋ฒ๊น ์ธ์ ์ ์ค์ ํฉ๋๋ค.
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js Debug",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/next/dist/bin/next",
"args": ["dev"],
"cwd": "${workspaceFolder}",
"protocol": "inspector",
"runtimeArgs": ["--inspect"],
"port": 9229
}
]
}
VS Code์์ F5๋ฅผ ๋๋ฌ ๋๋ฒ๊น ์ ์์ํ ์ ์์ต๋๋ค.
โ 3. ํด๋ผ์ด์ธํธ ์ฌ์ด๋ ๋๋ฒ๊น
React Developer Tools
- Component Tree: ํ์ฌ ๋ ๋๋ง ์ค์ธ ์ปดํฌ๋ํธ ๊ตฌ์กฐ ํ์ธ
- Props/State: ๊ฐ ์ปดํฌ๋ํธ์ ์ํ์ ์์ฑ ํ์ธ
- Hooks: useState, useEffect ๋ฑ ์ํ ๋ณํ ์ถ์
Error Boundary ํ์ฉ
์์์น ๋ชปํ ์ค๋ฅ๋ก ์ธํด ์ ํ๋ฆฌ์ผ์ด์ ์ด ์ค๋จ๋์ง ์๋๋ก ์๋ฌ ๊ฒฝ๊ณ๋ฅผ ์ถ๊ฐํฉ๋๋ค.
// app/ErrorBoundary.tsx
import React from "react";
class ErrorBoundary extends React.Component {
state = { hasError: false };
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidCatch(error: Error, info: React.ErrorInfo) {
console.error("Error ๋ฐ์:", error, info);
}
render() {
if (this.state.hasError) {
return <h1>์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค.</h1>;
}
return this.props.children;
}
}
export default ErrorBoundary;
โ 4. ์๋ฒ ์ฌ์ด๋ ๋๋ฒ๊น
์๋ฒ ๋ก๊ทธ ํ์ฉ
Next.js ์๋ฒ ๋ก๊ทธ๋ ํฐ๋ฏธ๋์ ์ถ๋ ฅ๋ฉ๋๋ค.
export async function getServerSideProps() {
console.log("์๋ฒ์์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๋ ์ค...");
return { props: {} };
}
ํ๊ฒฝ ๋ณ์ ํ์ธ
console.log("ํ๊ฒฝ ๋ณ์:", process.env.NEXT_PUBLIC_API_URL);
๋๋ฒ๊ทธ ๋ชจ๋ ํ์ฑํ
๊ฐ๋ฐ ๋ชจ๋์์ ์๋ฒ๋ฅผ ๋๋ฒ๊ทธ ๋ชจ๋๋ก ์คํํฉ๋๋ค.
NODE_OPTIONS='--inspect' npm run dev
๋๋ฒ๊ฑฐ๊ฐ ํ์ฑํ๋๋ฉด VS Code์์ ์ฐ๊ฒฐํ์ฌ ๋๋ฒ๊น ํ ์ ์์ต๋๋ค.
โ 5. ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
Web Vitals ํ์ฉ
ํ์ด์ง ์ฑ๋ฅ์ ๋ถ์ํ์ฌ ์ฑ๋ฅ ์ ํ ์์ธ์ ํ์ ํฉ๋๋ค.
'use client';
import { useReportWebVitals } from 'next/web-vitals';
export default function WebVitalsLogger() {
useReportWebVitals((metric) => {
console.log(metric);
});
return null;
}
Lighthouse ๋ถ์
- ์ฑ๋ฅ ์งํ: ํ์ด์ง ๋ก๋ฉ ์๋, ์ธํฐ๋ํฐ๋ธ์ฑ ํ๊ฐ
- SEO ์ฒดํฌ: ๋ฉํ ํ๊ทธ ๋ฐ ์ ๊ทผ์ฑ ํ์ธ
- ์ต์ ํ ์ ์: ์ด๋ฏธ์ง ์์ถ, ์ฝ๋ ์คํ๋ฆฌํ ๋ฑ
โ 6. ๋ฐํ์ ์ค๋ฅ ๋๋ฒ๊น
Sentry๋ฅผ ์ฌ์ฉํ์ฌ ์ค๋ฅ ๋ชจ๋ํฐ๋ง
Sentry๋ Next.js ํ๋ก์ ํธ์์ ๋ฐ์ํ๋ ์ค๋ฅ๋ฅผ ๋ชจ๋ํฐ๋งํ๊ณ ๋ณด๊ณ ํ ์ ์์ต๋๋ค.
์ค์น
npm install @sentry/nextjs
์ค์
// sentry.client.config.js
import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
});
์๋ฌ ๋ฐ์ ์ Sentry ๋์๋ณด๋์์ ์ค์๊ฐ์ผ๋ก ํ์ธํ ์ ์์ต๋๋ค.
โ 7. ์ฝ๋ ํ์ง ๊ฒ์ฆ
ESLint์ Prettier ์ค์
์ฝ๋ฉ ํ์ค์ ์ค์ํ์ฌ ๋๋ฒ๊น ์๊ฐ์ ์ค์ ๋๋ค.
npm install eslint prettier eslint-plugin-react
์ค์ ํ์ผ
// .eslintrc.json
{
"extends": ["next", "prettier"],
"plugins": ["react"]
}
์คํฌ๋ฆฝํธ ์ถ๊ฐ
"scripts": {
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
}
โ ์์ฝ
๋๋ฒ๊น ๋๊ตฌ ์ฃผ์ ๊ธฐ๋ฅ ํ์ฉ ์์
VS Code ๋๋ฒ๊ฑฐ | ์๋ฒ ๋๋ฒ๊น | ์ฝ๋ ์ค๋ฅ ๋ฐ ๋ณ์ ํ์ธ |
Chrome DevTools | ํด๋ผ์ด์ธํธ ๋๋ฒ๊น | ์ํ ๊ด๋ฆฌ ๋ฐ ์ฑ๋ฅ ์ธก์ |
React Developer Tools | ์ํ, props, hooks ๋ชจ๋ํฐ๋ง | ์ปดํฌ๋ํธ ํธ๋ฆฌ ๋๋ฒ๊น |
Error Boundary | ์์ธ ์ฒ๋ฆฌ ๋ฐ ์ค๋ฅ ๋ณต๊ตฌ | ํด๋ผ์ด์ธํธ ์ค๋ฅ ๋ฐฉ์ง |
Sentry | ๋ฐํ์ ์ค๋ฅ ๋ชจ๋ํฐ๋ง | ์๋ฒ ๋ฐ ํด๋ผ์ด์ธํธ ์ค๋ฅ ์ถ์ |
Web Vitals | ์ฑ๋ฅ ๋ฐ์ดํฐ ์์ง | ํ์ด์ง ์ฑ๋ฅ ์ต์ ํ |
Next.js, ๋๋ฒ๊น , VS Code, Chrome DevTools, React Developer Tools, Sentry, Web Vitals, ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง, ๋ฐํ์ ์ค๋ฅ, ์ฝ๋ ํ์ง, SEO ์ต์ ํ
'framework > NextJS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ Next.js Draft Mode ์ฌ์ฉ ๊ฐ์ด๋ (0) | 2025.05.14 |
---|---|
๐ ๏ธ Next.js์์ ์ปค์คํ ์๋ฒ(Custom Server) ๊ตฌ์ถํ๊ธฐ (0) | 2025.05.12 |
๐ NestJS ModuleRef โ ๋์ ๋ชจ๋ ์ธ์คํด์ค ์ฃผ์ ์์ ๊ฐ์ด๋ (0) | 2025.05.12 |
๐จ Next.js App Router์์ CSS-in-JS ์ฌ์ฉํ๊ธฐ (0) | 2025.05.09 |
๐ก๏ธ Next.js Content Security Policy(CSP) ์ค์ ๊ฐ์ด๋ (0) | 2025.05.09 |
- Total
- Today
- Yesterday
- nextJS
- github
- Webpack
- REACT
- AI์ฑ๋ด
- rag
- CI/CD
- Prisma
- ๋ฐฑ์๋๊ฐ๋ฐ
- ํ์ด์ฌ ์๊ณ ๋ฆฌ์ฆ
- App Router
- gatsbyjs
- kotlin
- Next.js
- ํ๋ก ํธ์๋๋ฉด์
- NestJS
- Ktor
- SEO์ต์ ํ
- seo ์ต์ ํ 10๊ฐ
- ๊ด๋ฆฌ์
- PostgreSQL
- ์น๊ฐ๋ฐ
- llm
- ๊ฐ๋ฐ๋ธ๋ก๊ทธ
- Docker
- fastapi
- Python
- LangChain
- nodejs
- ํ๋ก ํธ์๋
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |