Ver3.0 ๐ ํ์ ์คํฌ๋ฆฝํธ๋ก ๋ง๋๋ ์ ์ ์ฌ์ดํธ, Gatsby์ ํจ๊ปํ๋ ํ์ ์์ ํ GraphQL ์ฌํ

๐ ํ์ ์คํฌ๋ฆฝํธ๋ก ๋ง๋๋ ์ ์ ์ฌ์ดํธ, Gatsby์ ํจ๊ปํ๋ ํ์ ์์ ํ GraphQL ์ฌํ
์๋ ! ์ค๋์ ์ ๋ง ์ฌ๋ฏธ์๋ ์ฃผ์ ๋ฅผ ๊ฐ์ง๊ณ ์์ด. ๋ฐ๋ก ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ฅผ ํ์ฉํ ์ ์ ์ฌ์ดํธ ์์ฑ์ ๋ํ ์ด์ผ๊ธฐ์ผ. ์์ฆ ์น ๊ฐ๋ฐ ํธ๋ ๋๋ฅผ ๋ณด๋ฉด ์ ์ ์ฌ์ดํธ ์์ฑ(Static Site Generation, SSG)์ด ์ ๋ง ํซํ์์? ๊ทธ๋ฐ๋ฐ ์ฌ๊ธฐ์ ํ์ ์คํฌ๋ฆฝํธ์ ํ์ ์์ ์ฑ๊น์ง ๋ํ๋ฉด ์ ๋ง ๊ฐ๋ ฅํ ์กฐํฉ์ด ๋๊ฑฐ๋ . ๐ฏ
ํนํ Gatsby๋ GraphQL์ ๊ธฐ๋ณธ์ผ๋ก ์ฌ์ฉํ๋๋ฐ, ์ด๊ฑธ ํ์ ์คํฌ๋ฆฝํธ์ ๊ฒฐํฉํ๋ฉด ๋ง์น ์ํผํ์ด๋ก ํ์ ๊ฐ์ ๋๋์ด์ผ. ๋ฐ์ดํฐ ์ฟผ๋ฆฌ๋ถํฐ ์ปดํฌ๋ํธ๊น์ง ๋ชจ๋ ๊ฒ ํ์ ์์ ํ๊ฒ ๊ด๋ฆฌ๋๋๊น ๋ง์ด์ผ. ์, ๊ทธ๋ผ ์ด ๋ฉ์ง ์ธ๊ณ๋ก ํจ๊ป ๋ ๋๋ณผ๊น?
๐จ์ ์ ์ฌ์ดํธ ์์ฑ, ์ ์ด๋ ๊ฒ ์ธ๊ธฐ๊ฐ ๋ง์๊น?
๋จผ์ ์ ์ ์ฌ์ดํธ ์์ฑ์ด ๋ญ์ง๋ถํฐ ์ด์ผ๊ธฐํด๋ณด์. ์ ํต์ ์ธ ์น์ฌ์ดํธ๋ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๋๋ง๋ค ์๋ฒ์์ HTML์ ์์ฑํด์ ๋ณด๋ด์คฌ์ด. ์ด๊ฑธ SSR(Server-Side Rendering)์ด๋ผ๊ณ ํ์ง. ๊ทธ๋ฐ๋ฐ ์ ์ ์ฌ์ดํธ ์์ฑ์ ๋น๋ ํ์์ ๋ฏธ๋ฆฌ ๋ชจ๋ ํ์ด์ง๋ฅผ HTML๋ก ๋ง๋ค์ด๋๋ ๊ฑฐ์ผ.
๐ก ์ ์ ์ฌ์ดํธ์ ํต์ฌ ์ฅ์
๋น๋ ์์ ์ ๋ชจ๋ ํ์ด์ง๊ฐ ์์ฑ๋๊ธฐ ๋๋ฌธ์ ์ฌ์ฉ์ ์์ฒญ์ด ๋ค์ด์ค๋ฉด ๊ทธ๋ฅ ํ์ผ์ ๋ณด๋ด์ฃผ๊ธฐ๋ง ํ๋ฉด ๋ผ. ์๋ฒ์์ ๋ณต์กํ ์ฐ์ฐ์ ํ ํ์๊ฐ ์์ผ๋ ์์ฒญ๋๊ฒ ๋น ๋ฅด๊ณ , CDN์ ๋ฐฐํฌํ๋ฉด ์ ์ธ๊ณ ์ด๋์๋ ๋น ๋ฅธ ์๋๋ก ์ ๊ทผํ ์ ์์ด!
์ด๋ฐ ๋ฐฉ์์ ์ฅ์ ์ ์ ๋ง ๋ง์. ์ฒซ์งธ๋ก ์ฑ๋ฅ์ด ์๋์ ์ด์ผ. ์ด๋ฏธ ๋ง๋ค์ด์ง HTML ํ์ผ์ ๋ณด๋ด์ฃผ๊ธฐ๋ง ํ๋ฉด ๋๋๊น ์๋ต ์๋๊ฐ ๋ฐ๋ฆฌ์ด ๋จ์๋ก ๋นจ๋ผ. ๋์งธ๋ก ๋ณด์์ด ๊ฐํ๋ผ. ์๋ฒ ์ฌ์ด๋ ๋ก์ง์ด ์์ผ๋ ๊ณต๊ฒฉ ํ๋ฉด์ด ์ค์ด๋ค๊ฑฐ๋ . ์ ์งธ๋ก ํธ์คํ ๋น์ฉ์ด ์ ๋ ดํด. Netlify, Vercel ๊ฐ์ ๊ณณ์์ ๋ฌด๋ฃ๋ก ํธ์คํ ํ ์๋ ์์ด!
๋ฌผ๋ก ๋จ์ ๋ ์์ด. ์ฝํ ์ธ ๊ฐ ๋ฐ๋ ๋๋ง๋ค ๋ค์ ๋น๋ํด์ผ ํ๊ณ , ํ์ด์ง๊ฐ ์์ฒ ๊ฐ๋ฉด ๋น๋ ์๊ฐ์ด ๊ธธ์ด์ง ์ ์์ง. ํ์ง๋ง Gatsby๋ ์ด๋ฐ ๋ฌธ์ ๋ค์ ํด๊ฒฐํ๊ธฐ ์ํ ๋ค์ํ ์ต์ ํ ๊ธฐ๋ฒ์ ์ ๊ณตํด. Incremental Builds๋ผ๋ ์ง, Deferred Static Generation ๊ฐ์ ๊ธฐ๋ฅ๋ค ๋ง์ด์ผ. ๐
โกGatsby, ์ ์ ์ฌ์ดํธ ์์ฑ์ ๊ฐ์
Gatsby๋ React ๊ธฐ๋ฐ์ ์ ์ ์ฌ์ดํธ ์์ฑ ํ๋ ์์ํฌ์ผ. 2015๋ ์ ์ฒ์ ๋ฑ์ฅํ๋๋ฐ, ์ง๊ธ์ ์ ์ ์ฌ์ดํธ ์์ฑ ๋ถ์ผ์์ ๊ฐ์ฅ ์ธ๊ธฐ ์๋ ๋๊ตฌ ์ค ํ๋๊ฐ ๋์ด. Gatsby์ ๊ฐ์ฅ ํฐ ํน์ง์ GraphQL์ ๋ฐ์ดํฐ ๋ ์ด์ด๋ก ์ฌ์ฉํ๋ค๋ ์ ์ด์ผ.
โจ Gatsby์ ํต์ฌ ์ฒ ํ
Gatsby๋ "๋ชจ๋ ๋ฐ์ดํฐ ์์ค๋ฅผ GraphQL๋ก ํตํฉํ๋ค"๋ ์ฒ ํ์ ๊ฐ์ง๊ณ ์์ด. ๋งํฌ๋ค์ด ํ์ผ์ด๋ , CMS๋ , REST API๋ , ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ ์๊ด์์ด ๋ชจ๋ GraphQL ์ฟผ๋ฆฌ๋ก ์ ๊ทผํ ์ ์๊ฒ ๋ง๋ค์ด์ค. ์ด๊ฒ ์ ๋ง ๊ฐ๋ ฅํ ์ถ์ํ์ผ!
Gatsby์ ์๋ ๋ฐฉ์์ ๊ฐ๋จํ ์ค๋ช ํ๋ฉด ์ด๋. ๋จผ์ ๋น๋ ํ์์ ๋ค์ํ ์์ค์์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์. ์ด ๋ฐ์ดํฐ๋ค์ GraphQL ์คํค๋ง๋ก ๋ณํํ๊ณ , ๊ฐ๋ฐ์๋ GraphQL ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์. ๊ทธ๋ฆฌ๊ณ React ์ปดํฌ๋ํธ์์ ์ด ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํด์ ํ์ด์ง๋ฅผ ๋ ๋๋งํ๋ ๊ฑฐ์ง. ๋ง์ง๋ง์ผ๋ก ๋ชจ๋ ํ์ด์ง๋ฅผ ์ ์ HTML๋ก ์์ฑํด์ ๋ฐฐํฌํด.
์ฌ๊ธฐ์ ์ค์ํ ๊ฑด ๋น๋ ํ์์ ๋ชจ๋ ๋ฐ์ดํฐ ํ์นญ์ด ์๋ฃ๋๋ค๋ ๊ฑฐ์ผ. ๋ฐํ์์ API๋ฅผ ํธ์ถํ ํ์๊ฐ ์์ผ๋ ์ฌ์ฉ์๋ ์ฆ์ ์ฝํ ์ธ ๋ฅผ ๋ณผ ์ ์์ด. ๋ฌผ๋ก ํ์ํ๋ฉด ํด๋ผ์ด์ธํธ ์ฌ์ด๋์์ ์ถ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์๋ ์์ง๋ง, ๊ธฐ๋ณธ์ ์ผ๋ก๋ ๋ชจ๋ ๊ฒ ๋น๋ ํ์์ ๊ฒฐ์ ๋ผ.
์ ๋ค์ด์ด๊ทธ๋จ์ ๋ณด๋ฉด Gatsby์ ๋น๋ ํ๋ก์ธ์ค๊ฐ ํ๋์ ๋ค์ด์ค์ง? ๋ฐ์ดํฐ ์์ค์์ ์์ํด์ GraphQL๋ก ํตํฉ๋๊ณ , React ์ปดํฌ๋ํธ๋ก ๋ ๋๋ง๋๊ณ , ์ต์ข ์ ์ผ๋ก ์ ์ HTML์ด ์์ฑ๋๋ ํ๋ฆ์ด์ผ. ์ด ๋ชจ๋ ๊ณผ์ ์ด ๋น๋ ํ์์ ์ผ์ด๋๊ธฐ ๋๋ฌธ์ ์ฌ์ฉ์๋ ์์ฒญ๋๊ฒ ๋น ๋ฅธ ๊ฒฝํ์ ํ๊ฒ ๋ผ. โก
๐ทํ์ ์คํฌ๋ฆฝํธ, ์ ํ์๊ฐ ๋์๊น?
์, ์ด์ ํ์ ์คํฌ๋ฆฝํธ ์ด์ผ๊ธฐ๋ฅผ ํด๋ณด์. ํ์ ์คํฌ๋ฆฝํธ๋ ์๋ฐ์คํฌ๋ฆฝํธ์ ์ ์ ํ์ ์์คํ ์ ์ถ๊ฐํ ์ธ์ด์ผ. ๋ง์ดํฌ๋ก์ํํธ๊ฐ 2012๋ ์ ๋ง๋ค์๋๋ฐ, ์ง๊ธ์ ํ๋ก ํธ์๋ ๊ฐ๋ฐ์ ์ฌ์ค์ ํ์ค์ด ๋์ด.
ํ์ ์คํฌ๋ฆฝํธ๊ฐ ์ ์ด๋ ๊ฒ ์ธ๊ธฐ๊ฐ ๋ง์๊น? ๊ฐ์ฅ ํฐ ์ด์ ๋ ๊ฐ๋ฐ ๊ฒฝํ(Developer Experience, DX)์ ํฅ์์ด์ผ. ์ฝ๋๋ฅผ ์์ฑํ๋ ์๊ฐ๋ถํฐ IDE๊ฐ ์๋์์ฑ์ ์ ๊ณตํ๊ณ , ํ์ ์ค๋ฅ๋ฅผ ๋ฏธ๋ฆฌ ์ก์์ฃผ๊ณ , ๋ฆฌํฉํ ๋ง์ ์์ ํ๊ฒ ํ ์ ์๊ฒ ๋์์ค. ์ด๊ฑด ์ ๋ง ํฐ ์ฐจ์ด์ผ!
๐ฏ ์ค์ ์ฌ๋ก๋ก ๋ณด๋ ํ์ ์คํฌ๋ฆฝํธ์ ์๋ ฅ
์๋ฅผ ๋ค์ด๋ณผ๊ฒ. ์๋ฐ์คํฌ๋ฆฝํธ์์ ํจ์๋ฅผ ์์ฑํ๋๋ฐ, ๋์ค์ ๊ทธ ํจ์์ ํ๋ผ๋ฏธํฐ ์์๋ฅผ ๋ฐ๊ฟ์ผ ํ๋ค๊ณ ์๊ฐํด๋ด. ์๋ฐ์คํฌ๋ฆฝํธ๋ผ๋ฉด ๋ชจ๋ ํธ์ถ ๋ถ๋ถ์ ์ผ์ผ์ด ์ฐพ์์ ์์ ํด์ผ ํด. ๊ทธ๋ฐ๋ฐ ํ์ ์คํฌ๋ฆฝํธ๋? IDE๊ฐ ๋ชจ๋ ํธ์ถ ๋ถ๋ถ์ ์ฐพ์์ฃผ๊ณ , ํ์ ์ด ๋ง์ง ์์ผ๋ฉด ๋นจ๊ฐ ์ค๋ก ํ์ํด์ค. ๋ฆฌํฉํ ๋ง์ด ์ ๋ง ์์ ํด์ง๋ ๊ฑฐ์ง!
ํ์ ์คํฌ๋ฆฝํธ์ ๋ ๋ค๋ฅธ ์ฅ์ ์ ์ฝ๋์ ๋ฌธ์ํ ํจ๊ณผ์ผ. ํ์ ์ ์ ์์ฒด๊ฐ ์ฝ๋์ ์๋๋ฅผ ๋ช ํํ๊ฒ ์ ๋ฌํด์ฃผ๊ฑฐ๋ . ์๋ฅผ ๋ค์ด ์ด๋ฐ ํจ์๊ฐ ์๋ค๊ณ ํด๋ณด์:
function createUser(name: string, age: number, email: string): User {
return {
id: generateId(),
name,
age,
email,
createdAt: new Date()
};
}
์ด ํจ์๋ฅผ ๋ณด๋ฉด ์ด๋ค ํ๋ผ๋ฏธํฐ๊ฐ ํ์ํ์ง, ์ด๋ค ํ์ ์ด์ด์ผ ํ๋์ง, ๋ฌด์์ ๋ฐํํ๋์ง๊ฐ ํ๋์ ๋ค์ด์. ๋ณ๋์ ๋ฌธ์๊ฐ ํ์ ์์ด! ๊ทธ๋ฆฌ๊ณ ์ด ํจ์๋ฅผ ์ฌ์ฉํ๋ ์ฌ๋์ด ์๋ชป๋ ํ์ ์ ์ ๋ฌํ๋ฉด ์ปดํ์ผ ํ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํด์ ๋ฐํ์ ๋ฒ๊ทธ๋ฅผ ๋ฏธ๋ฆฌ ๋ฐฉ์งํ ์ ์์ด.
ํนํ ํ ํ๋ก์ ํธ์์ ํ์ ์คํฌ๋ฆฝํธ์ ๊ฐ์น๋ ๋์ฑ ๋น๋. ์ฌ๋ฌ ์ฌ๋์ด ํ์ ํ ๋ ํ์ ์์คํ ์ด ์ผ์ข ์ ๊ณ์ฝ(Contract) ์ญํ ์ ํด์ฃผ๊ฑฐ๋ . "์ด ํจ์๋ ์ด๋ฐ ํ์ ์ ๋ฐ๊ณ ์ ๋ฐ ํ์ ์ ๋ฐํํ๋ค"๋ ๋ช ํํ ์ฝ์์ด ์์ผ๋๊น ์๋ก ๋ฏฟ๊ณ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ด. ๐ค
๐Gatsby + TypeScript, ์๋ฒฝํ ์กฐํฉ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก Gatsby์ ํ์
์คํฌ๋ฆฝํธ๋ฅผ ๊ฒฐํฉํ๋ ์ด์ผ๊ธฐ๋ฅผ ํด๋ณด์. Gatsby๋ ๋ฒ์ 2.5๋ถํฐ ํ์
์คํฌ๋ฆฝํธ๋ฅผ ๊ณต์ ์ง์ํ๊ธฐ ์์ํ์ด. ๋ณ๋์ ์ค์ ์์ด๋ .tsx ํ์ผ์ ๋ง๋ค๋ฉด ๋ฐ๋ก ํ์
์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ์ ์์ง.
Gatsby ํ๋ก์ ํธ์์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์์ํ๋ ๊ฑด ์ ๋ง ๊ฐ๋จํด. ์ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค ๋ ํ์ ์คํฌ๋ฆฝํธ ์คํํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ผ:
gatsby new my-typescript-site https://github.com/gatsbyjs/gatsby-starter-default-typescript
๋๋ ๊ธฐ์กด ํ๋ก์ ํธ์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ถ๊ฐํ๊ณ ์ถ๋ค๋ฉด ์ด๋ ๊ฒ ํ๋ฉด ๋ผ:
npm install --save-dev typescript @types/react @types/react-dom @types/node
// tsconfig.json ์์ฑ
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"lib": ["DOM", "ES2018"],
"jsx": "react",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node"
},
"include": ["./src/**/*"]
}
์ด์ .js ํ์ผ์ .tsx๋ก ๋ฐ๊พธ๊ธฐ๋ง ํ๋ฉด ํ์
์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ์ ์์ด. ์ ๋ง ๊ฐ๋จํ์ง? ๐
โ ๏ธ ์ฃผ์ํ ์
Gatsby์์ ํ์
์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ๋ ํ ๊ฐ์ง ์ฃผ์ํ ์ ์ด ์์ด. gatsby-node.js, gatsby-config.js ๊ฐ์ Gatsby ์ค์ ํ์ผ๋ค์ Node.js ํ๊ฒฝ์์ ์คํ๋๊ธฐ ๋๋ฌธ์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์
์คํฌ๋ฆฝํธ๋ฅผ ์ง์ํ์ง ์์. ์ด ํ์ผ๋ค์์๋ ํ์
์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด ์ถ๊ฐ ์ค์ ์ด ํ์ํด.
Gatsby์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ํจ๊ป ์ฌ์ฉํ๋ฉด ์ ๋ง ๋ง์ ์ด์ ์ด ์์ด. ์ฒซ์งธ๋ก, ์ปดํฌ๋ํธ์ props๊ฐ ํ์ ์์ ํด์ ธ. ๋์งธ๋ก, ํ์ด์ง ์ปดํฌ๋ํธ์ ๋ฐ์ดํฐ ๊ตฌ์กฐ๊ฐ ๋ช ํํด์ ธ. ์ ์งธ๋ก, ๋น๋ ํ์์ ๋ง์ ์ค๋ฅ๋ฅผ ์ก์ ์ ์์ด. ์ด๊ฑด ์ ๋ง ํฐ ์ฅ์ ์ด์ผ!
๐GraphQL, ๋ฐ์ดํฐ ํ์นญ์ ํ๋ช
์ด์ GraphQL์ ๋ํด ์ด์ผ๊ธฐํด๋ณด์. GraphQL์ ํ์ด์ค๋ถ(ํ Meta)์ด 2012๋ ์ ๊ฐ๋ฐํ๊ณ 2015๋ ์ ์คํ์์ค๋ก ๊ณต๊ฐํ ์ฟผ๋ฆฌ ์ธ์ด์ผ. REST API์ ์ฌ๋ฌ ๋ฌธ์ ์ ๋ค์ ํด๊ฒฐํ๊ธฐ ์ํด ๋ง๋ค์ด์ก์ด.
GraphQL์ ๊ฐ์ฅ ํฐ ํน์ง์ ํด๋ผ์ด์ธํธ๊ฐ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ์ ํํ ์์ฒญํ ์ ์๋ค๋ ๊ฑฐ์ผ. REST API์์๋ ์๋ํฌ์ธํธ๊ฐ ๋ฐํํ๋ ๋ฐ์ดํฐ ๊ตฌ์กฐ๊ฐ ๊ณ ์ ๋์ด ์์์? ๊ทธ๋์ ํ์ ์๋ ๋ฐ์ดํฐ๋ ๋ฐ๊ฒ ๋๊ฑฐ๋(Over-fetching), ์ฌ๋ฌ ์๋ํฌ์ธํธ๋ฅผ ํธ์ถํด์ผ ํ๋(Under-fetching) ๋ฌธ์ ๊ฐ ์๊ฒจ.
๐ก REST vs GraphQL ๋น๊ต
REST API๋ก ์ฌ์ฉ์ ์ ๋ณด์ ๊ทธ ์ฌ์ฉ์์ ๊ฒ์๊ธ์ ๊ฐ์ ธ์จ๋ค๊ณ ์๊ฐํด๋ด. /users/1์ ํธ์ถํ๊ณ , ๋ค์ /users/1/posts๋ฅผ ํธ์ถํด์ผ ํด. ๋ ๋ฒ์ ๋คํธ์ํฌ ์์ฒญ์ด ํ์ํ์ง. ๊ทธ๋ฐ๋ฐ GraphQL์? ํ ๋ฒ์ ์ฟผ๋ฆฌ๋ก ๋ชจ๋ ๊ฑธ ๊ฐ์ ธ์ฌ ์ ์์ด!
GraphQL ์ฟผ๋ฆฌ๋ ์ด๋ ๊ฒ ์๊ฒผ์ด:
query {
user(id: "1") {
name
email
posts {
title
content
createdAt
}
}
}
๋ณด๊ธฐ๋ง ํด๋ ์ง๊ด์ ์ด์ง? ํ์ํ ํ๋๋ง ์ ํํ ๋ช ์ํ ์ ์์ด. ๊ทธ๋ฆฌ๊ณ ์ด ์ฟผ๋ฆฌ์ ๊ฒฐ๊ณผ๋ ์ฟผ๋ฆฌ์ ๊ตฌ์กฐ์ ์ ํํ ์ผ์นํ๋ JSON์ผ๋ก ๋ฐํ๋ผ. ์ด๊ฒ GraphQL์ ๊ฐ๋ ฅํ ์ ์ด์ผ!
Gatsby์์ GraphQL์ ์ ๋ง ์ค์ฌ์ ์ธ ์ญํ ์ ํด. ๋ชจ๋ ๋ฐ์ดํฐ ์์ค๊ฐ GraphQL๋ก ํตํฉ๋๊ธฐ ๋๋ฌธ์, ๋ฐ์ดํฐ๊ฐ ์ด๋์ ์ค๋ ์๊ด์์ด ๋์ผํ ๋ฐฉ์์ผ๋ก ์ ๊ทผํ ์ ์์ด. ๋งํฌ๋ค์ด ํ์ผ์ด๋ , Contentful ๊ฐ์ CMS๋ , WordPress๋ , ์ฌ์ง์ด JSON ํ์ผ์ด๋ ๋ชจ๋ GraphQL ์ฟผ๋ฆฌ๋ก ๊ฐ์ ธ์ฌ ์ ์์ง. ๐ฏ
์ ๋ค์ด์ด๊ทธ๋จ์ ๋ณด๋ฉด GraphQL์ด ์ด๋ป๊ฒ ๋ค์ํ ๋ฐ์ดํฐ ์์ค๋ฅผ ํตํฉํ๋์ง ์ ์ ์์ด. ์ด๊ฒ ๋ฐ๋ก Gatsby์ ํต์ฌ ์์ด๋์ด์ผ. ๋ฐ์ดํฐ๊ฐ ์ด๋์ ์ค๋ ์๊ด์์ด ๊ฐ๋ฐ์๋ GraphQL ์ฟผ๋ฆฌ๋ง ์์ฑํ๋ฉด ๋ผ. ์ ๋ง ํธ๋ฆฌํ์ง? ๐
๐ก๏ธํ์ ์์ ํ GraphQL, ์ด๋ป๊ฒ ๊ตฌํํ ๊น?
์, ์ด์ ํต์ฌ ์ฃผ์ ๋ก ๋ค์ด๊ฐ๋ณด์. Gatsby์์ GraphQL์ ์ฌ์ฉํ ๋ ํ์ ์์ ์ฑ์ ํ๋ณดํ๋ ๋ฐฉ๋ฒ์ด์ผ. ๊ธฐ๋ณธ์ ์ผ๋ก GraphQL ์ฟผ๋ฆฌ๋ ๋ฌธ์์ด์ด์์? ๊ทธ๋์ ํ์ ์คํฌ๋ฆฝํธ๊ฐ ์๋์ผ๋ก ํ์ ์ ์ถ๋ก ํ ์ ์์ด. ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ด ๋ฐ๋ก GraphQL Code Generator์ผ!
GraphQL Code Generator๋ GraphQL ์คํค๋ง์ ์ฟผ๋ฆฌ๋ฅผ ๋ถ์ํด์ ํ์ ์คํฌ๋ฆฝํธ ํ์ ์ ์๋ฅผ ์๋์ผ๋ก ์์ฑํด์ฃผ๋ ๋๊ตฌ์ผ. ์ด๊ฑธ ์ฌ์ฉํ๋ฉด GraphQL ์ฟผ๋ฆฌ์ ๊ฒฐ๊ณผ๊ฐ ์๋ฒฝํ๊ฒ ํ์ ์์ ํด์ ธ. ์ค์น๋ ์ด๋ ๊ฒ ํด:
npm install --save-dev @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations @graphql-codegen/typescript-react-apollo
๊ทธ๋ฆฌ๊ณ ํ๋ก์ ํธ ๋ฃจํธ์ codegen.yml ํ์ผ์ ๋ง๋ค์ด:
overwrite: true
schema: "http://localhost:8000/___graphql"
documents: "src/**/*.tsx"
generates:
src/generated/graphql.ts:
plugins:
- "typescript"
- "typescript-operations"
config:
avoidOptionals: false
maybeValue: T | null
์ด์ Gatsby ๊ฐ๋ฐ ์๋ฒ๋ฅผ ์คํํ๊ณ ์ฝ๋ ์์ฑ ๋ช ๋ น์ ์คํํ๋ฉด ๋ผ:
gatsby develop
npm run codegen
๐ฏ ์๋ ํ์ ์์ฑ์ ๋ง๋ฒ
์ฝ๋ ์์ฑ์ด ์๋ฃ๋๋ฉด src/generated/graphql.ts ํ์ผ์ด ์์ฑ๋ผ. ์ด ํ์ผ์๋ ๋ชจ๋ GraphQL ์ฟผ๋ฆฌ์ ๋ฎคํ
์ด์
์ ๋ํ ํ์
์ ์๊ฐ ๋ค์ด์์ด. ์ด์ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ฌ์ฉํ ๋ ์๋ฒฝํ ์๋์์ฑ๊ณผ ํ์
์ฒดํฌ๋ฅผ ๋ฐ์ ์ ์์ด!
์ค์ ๋ก ์ฌ์ฉํ๋ ์์๋ฅผ ๋ณด์. ๋จผ์ GraphQL ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด:
import { graphql } from 'gatsby';
export const query = graphql`
query BlogPostQuery($id: String!) {
markdownRemark(id: { eq: $id }) {
html
frontmatter {
title
date
author
tags
}
}
}
`;
์ฝ๋ ์์ฑ์ ์คํํ๋ฉด BlogPostQuery๋ผ๋ ํ์
์ด ์๋์ผ๋ก ์์ฑ๋ผ. ์ด์ ํ์ด์ง ์ปดํฌ๋ํธ์์ ์ด ํ์
์ ์ฌ์ฉํ ์ ์์ด:
import React from 'react';
import { PageProps } from 'gatsby';
import { BlogPostQuery } from '../generated/graphql';
const BlogPost: React.FC<PageProps<BlogPostQuery>> = ({ data }) => {
const post = data.markdownRemark;
// ์๋ฒฝํ ํ์
์์ ์ฑ!
// post.frontmatter.title์ string ํ์
// post.frontmatter.date๋ string ํ์
// IDE๊ฐ ๋ชจ๋ ํ๋๋ฅผ ์๋์์ฑํด์ค
return (
<article>
<h1>{post?.frontmatter?.title}</h1>
<time>{post?.frontmatter?.date}</time>
<div dangerouslySetInnerHTML={{ __html: post?.html || '' }} />
</article>
);
};
export default BlogPost;
๋ณด์ด์ง? data ๊ฐ์ฒด์ ๋ชจ๋ ํ๋๊ฐ ํ์
์์ ํด์ก์ด. IDE์์ ์๋์์ฑ๋ ์๋ฒฝํ๊ฒ ์๋ํ๊ณ , ์๋ชป๋ ํ๋์ ์ ๊ทผํ๋ ค๊ณ ํ๋ฉด ์ปดํ์ผ ํ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํด. ์ด๊ฒ ๋ฐ๋ก ํ์
์์ ํ GraphQL์ ์๋ ฅ์ด์ผ! ๐ช
๐จ์ค์ ์์ : ๋ธ๋ก๊ทธ ๋ง๋ค๊ธฐ
์ด๋ก ์ ์ถฉ๋ถํ ๋ฐฐ์ ์ผ๋ ์ด์ ์ค์ ์์ ๋ฅผ ๋ง๋ค์ด๋ณด์. ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ฅผ ์ฌ์ฉํด์ ๊ฐ๋จํ ๋ธ๋ก๊ทธ๋ฅผ ๋ง๋ค์ด๋ณผ ๊ฑฐ์ผ. ์ด ๊ณผ์ ์์ ํ์ ์์ ํ GraphQL ์ฟผ๋ฆฌ๋ฅผ ์ด๋ป๊ฒ ์์ฑํ๋์ง ์์ธํ ์์๋ณด์.
๋จผ์ ํ๋ก์ ํธ ๊ตฌ์กฐ๋ฅผ ์ก์๋ณด์:
my-blog/
โโโ src/
โ โโโ pages/
โ โ โโโ index.tsx
โ โ โโโ blog/
โ โ โโโ {MarkdownRemark.frontmatter__slug}.tsx
โ โโโ templates/
โ โ โโโ blog-post.tsx
โ โโโ components/
โ โ โโโ Layout.tsx
โ โ โโโ Header.tsx
โ โ โโโ PostCard.tsx
โ โโโ generated/
โ โ โโโ graphql.ts
โ โโโ types/
โ โโโ index.ts
โโโ content/
โ โโโ blog/
โ โโโ first-post.md
โ โโโ second-post.md
โโโ gatsby-config.ts
โโโ gatsby-node.ts
โโโ codegen.yml
๋จผ์ gatsby-config.ts๋ฅผ ์ค์ ํด์ผ ํด. ๋งํฌ๋ค์ด ํ์ผ์ ์ฝ๊ณ GraphQL๋ก ๋ณํํ๊ธฐ ์ํด ํ์ํ ํ๋ฌ๊ทธ์ธ๋ค์ ์ค์นํ์:
npm install gatsby-source-filesystem gatsby-transformer-remark
๊ทธ๋ฆฌ๊ณ gatsby-config.ts๋ฅผ ์์ฑํด:
import type { GatsbyConfig } from 'gatsby';
const config: GatsbyConfig = {
siteMetadata: {
title: '๋ด ๋ฉ์ง ๋ธ๋ก๊ทธ',
description: 'ํ์
์คํฌ๋ฆฝํธ์ Gatsby๋ก ๋ง๋ ๋ธ๋ก๊ทธ',
siteUrl: 'https://myblog.com',
},
plugins: [
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'blog',
path: `${__dirname}/content/blog`,
},
},
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
'gatsby-remark-prismjs',
'gatsby-remark-images',
],
},
},
],
};
export default config;
โจ ํ์ ์์ ํ Gatsby ์ค์
Gatsby 4๋ถํฐ๋ ์ค์ ํ์ผ๋ ํ์
์คํฌ๋ฆฝํธ๋ก ์์ฑํ ์ ์์ด! GatsbyConfig ํ์
์ ์ฌ์ฉํ๋ฉด ์ค์ ์ต์
์ ๋ํ ์๋์์ฑ๊ณผ ํ์
์ฒดํฌ๋ฅผ ๋ฐ์ ์ ์์ด. ์ ๋ง ํธ๋ฆฌํ์ง?
์ด์ ๋ธ๋ก๊ทธ ํฌ์คํธ ๋ชฉ๋ก์ ๋ณด์ฌ์ฃผ๋ ๋ฉ์ธ ํ์ด์ง๋ฅผ ๋ง๋ค์ด๋ณด์. src/pages/index.tsx:
import React from 'react';
import { graphql, Link, PageProps } from 'gatsby';
import { AllBlogPostsQuery } from '../generated/graphql';
export const query = graphql`
query AllBlogPosts {
allMarkdownRemark(
sort: { frontmatter: { date: DESC } }
) {
nodes {
id
frontmatter {
title
date(formatString: "YYYY๋
MM์ DD์ผ")
slug
excerpt
}
excerpt(pruneLength: 200)
}
}
}
`;
const IndexPage: React.FC<PageProps<AllBlogPostsQuery>> = ({ data }) => {
const posts = data.allMarkdownRemark.nodes;
return (
<main>
<h1>๋ธ๋ก๊ทธ ํฌ์คํธ</h1>
<div>
{posts.map(post => (
<article key={post.id}>
<h2>
<Link to={`/blog/${post.frontmatter?.slug}`}>
{post.frontmatter?.title}
</Link>
</h2>
<time>{post.frontmatter?.date}</time>
<p>{post.excerpt}</p>
</article>
))}
</div>
</main>
);
};
export default IndexPage;
์ฌ๊ธฐ์ ์ฃผ๋ชฉํ ์ ์ PageProps<AllBlogPostsQuery>์ผ. ์ด๋ ๊ฒ ์ ๋ค๋ฆญ ํ์
์ ์ฌ์ฉํ๋ฉด data prop์ด ์๋ฒฝํ๊ฒ ํ์
์์ ํด์ ธ. posts.map์ ํ ๋๋ ๊ฐ post์ ๊ตฌ์กฐ๋ฅผ IDE๊ฐ ์ ํํ ์๊ณ ์์ด์ ์๋์์ฑ์ด ์๋ฒฝํ๊ฒ ์๋ํด. ๐ฏ
์ด์ ๊ฐ๋ณ ๋ธ๋ก๊ทธ ํฌ์คํธ ํ์ด์ง๋ฅผ ๋ง๋ค์ด๋ณด์. Gatsby์ File System Route API๋ฅผ ์ฌ์ฉํ๋ฉด ๋์ ํ์ด์ง๋ฅผ ์ฝ๊ฒ ๋ง๋ค ์ ์์ด.
src/pages/blog/{MarkdownRemark.frontmatter__slug}.tsx:
import React from 'react';
import { graphql, PageProps } from 'gatsby';
import { BlogPostBySlugQuery } from '../../generated/graphql';
export const query = graphql`
query BlogPostBySlug($id: String!) {
markdownRemark(id: { eq: $id }) {
html
frontmatter {
title
date(formatString: "YYYY๋
MM์ DD์ผ")
author
tags
}
timeToRead
}
}
`;
const BlogPostPage: React.FC<PageProps<BlogPostBySlugQuery>> = ({ data }) => {
const post = data.markdownRemark;
if (!post) {
return <div>ํฌ์คํธ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.</div>;
}
return (
<article>
<header>
<h1>{post.frontmatter?.title}</h1>
<div>
<time>{post.frontmatter?.date}</time>
<span> ยท {post.timeToRead}๋ถ ์ฝ๊ธฐ</span>
<span> ยท {post.frontmatter?.author}</span>
</div>
<div>
{post.frontmatter?.tags?.map(tag => (
<span key={tag}>#{tag}</span>
))}
</div>
</header>
<div dangerouslySetInnerHTML={{ __html: post.html || '' }} />
</article>
);
};
export default BlogPostPage;
์๋ฒฝํ์ง? ๋ชจ๋ ๋ฐ์ดํฐ๊ฐ ํ์
์์ ํ๊ฒ ์ฒ๋ฆฌ๋๊ณ ์์ด. post.frontmatter?.tags๋ฅผ mapํ ๋๋ ํ์
์คํฌ๋ฆฝํธ๊ฐ ์ ํํ ์๊ณ ์์ด์ ์์ ํ๊ฒ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ด.
๐ ์ฌ๋ฅ๋ท์์ ๋ฐฐ์ฐ๋ ์ค์ ํ
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ๋ค์ํ ๊ฐ๋ฐ์๋ค์ ๊ฒฝํ์ ๊ณต์ ๋ฐ์ผ๋ฉด ์ด๋ฐ ์ค์ ๋ ธํ์ฐ๋ฅผ ๋ ๋น ๋ฅด๊ฒ ์ต๋ํ ์ ์์ด. ํนํ ํ์ ์คํฌ๋ฆฝํธ์ Gatsby ๊ฐ์ ์ต์ ๊ธฐ์ ์คํ์ ์ปค๋ฎค๋ํฐ์ ์ง์ ๊ณต์ ๊ฐ ์ ๋ง ์ค์ํ๊ฑฐ๋ !
๐ง๊ณ ๊ธ ํ์ ํจํด๊ณผ ์ ํธ๋ฆฌํฐ
์ด์ ์ข ๋ ๊ณ ๊ธ ์ฃผ์ ๋ก ๋์ด๊ฐ๋ณด์. Gatsby์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ํจ๊ป ์ฌ์ฉํ ๋ ์์๋๋ฉด ์ ์ฉํ ํ์ ํจํด๋ค์ด ์์ด. ์ด๋ฐ ํจํด๋ค์ ์ฌ์ฉํ๋ฉด ์ฝ๋์ ์ฌ์ฌ์ฉ์ฑ๊ณผ ํ์ ์์ ์ฑ์ ๋์ฑ ๋์ผ ์ ์์ด.
๋จผ์ ์ ๋ค๋ฆญ ์ปดํฌ๋ํธ ํจํด์ ์์๋ณด์. ์ฌ๋ฌ ์ข ๋ฅ์ ๋ฐ์ดํฐ๋ฅผ ํ์ํ๋ ์นด๋ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ ๋ค๊ณ ์๊ฐํด๋ด:
import React from 'react';
interface CardProps<T> {
data: T;
renderContent: (data: T) => React.ReactNode;
className?: string;
}
function Card<T>({ data, renderContent, className }: CardProps<T>) {
return (
<div className={`card ${className || ''}`}>
{renderContent(data)}
</div>
);
}
// ์ฌ์ฉ ์์
interface BlogPost {
title: string;
excerpt: string;
date: string;
}
const BlogPostCard: React.FC<{ post: BlogPost }> = ({ post }) => (
<Card
data={post}
renderContent={(post) => (
<>
<h3>{post.title}</h3>
<p>{post.excerpt}</p>
<time>{post.date}</time>
</>
)}
/>
);
์ด๋ ๊ฒ ์ ๋ค๋ฆญ์ ์ฌ์ฉํ๋ฉด ํ์
์์ ์ฑ์ ์ ์งํ๋ฉด์๋ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค ์ ์์ด. renderContent ํจ์ ์์์ post์ ํ์
์ด ์ ํํ ์ถ๋ก ๋๋ ๊ฑธ ๋ณผ ์ ์์ง?
๋ค์์ ์ ํธ๋ฆฌํฐ ํ์ ํ์ฉ์ด์ผ. ํ์ ์คํฌ๋ฆฝํธ๋ ์ ๋ง ๊ฐ๋ ฅํ ์ ํธ๋ฆฌํฐ ํ์ ๋ค์ ์ ๊ณตํด:
// Partial: ๋ชจ๋ ์์ฑ์ ์ ํ์ ์ผ๋ก ๋ง๋ฆ
type PartialBlogPost = Partial<BlogPost>;
// Pick: ํน์ ์์ฑ๋ง ์ ํ
type BlogPostPreview = Pick<BlogPost, 'title' | 'excerpt'>;
// Omit: ํน์ ์์ฑ์ ์ ์ธ
type BlogPostWithoutContent = Omit<BlogPost, 'html'>;
// Required: ๋ชจ๋ ์์ฑ์ ํ์๋ก ๋ง๋ฆ
type RequiredBlogPost = Required<BlogPost>;
// Record: ํค-๊ฐ ์์ ํ์
์ ์
type PostsBySlug = Record<string, BlogPost>;
// ์ค์ ์์: ํผ ์ํ ๊ด๋ฆฌ
interface BlogPostForm {
title: string;
content: string;
tags: string[];
published: boolean;
}
// ํผ ์๋ฌ ํ์
(๋ชจ๋ ํ๋๊ฐ ์ ํ์ ์๋ฌ ๋ฉ์์ง๋ฅผ ๊ฐ์ง)
type FormErrors = Partial<Record<keyof BlogPostForm, string>>;
const validateForm = (form: BlogPostForm): FormErrors => {
const errors: FormErrors = {};
if (!form.title) {
errors.title = '์ ๋ชฉ์ ์
๋ ฅํด์ฃผ์ธ์';
}
if (form.content.length < 10) {
errors.content = '๋ด์ฉ์ ์ต์ 10์ ์ด์์ด์ด์ผ ํฉ๋๋ค';
}
return errors;
};
์ด๋ฐ ์ ํธ๋ฆฌํฐ ํ์ ๋ค์ ์ ํ์ฉํ๋ฉด ์ค๋ณต ์ฝ๋๋ฅผ ์ค์ด๊ณ ํ์ ์์ ์ฑ์ ๋์ผ ์ ์์ด. ํนํ ํผ ์ฒ๋ฆฌ๋ ๋ฐ์ดํฐ ๋ณํ ๊ฐ์ ์์ ์์ ์ ๋ง ์ ์ฉํด!
๐ฏ ํ์ ๊ฐ๋
ํ์ ๊ฐ๋๋ ๋ฐํ์์ ํ์ ์ ์ขํ์ฃผ๋ ๊ธฐ๋ฒ์ด์ผ. GraphQL ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๊ฐ null์ผ ์ ์์ ๋ ํนํ ์ ์ฉํด:
function isValidPost(
post: BlogPost | null | undefined
): post is BlogPost {
return post !== null &&
post !== undefined &&
!!post.title;
}
// ์ฌ์ฉ
if (isValidPost(data.post)) {
// ์ด ๋ธ๋ก ์์์ post๋ BlogPost ํ์
console.log(post.title);
}
๐ ํ์ ๋ณํ
GraphQL ๊ฒฐ๊ณผ๋ฅผ ๋๋ฉ์ธ ๋ชจ๋ธ๋ก ๋ณํํ ๋ ํ์ ์์ ์ฑ์ ์ ์งํ๋ ๋ฐฉ๋ฒ:
type GQLPost = BlogPostQuery['post'];
function toPost(gqlPost: GQLPost): BlogPost {
if (!gqlPost) {
throw new Error('Invalid post');
}
return {
id: gqlPost.id,
title: gqlPost.frontmatter?.title ?? '',
content: gqlPost.html ?? '',
date: new Date(gqlPost.frontmatter?.date ?? '')
};
}
์ด๋ฐ ํจํด๋ค์ ์ตํ๋๋ฉด ๋ณต์กํ ํ์ ์๋๋ฆฌ์ค๋ ์์ ํ๊ฒ ์ฒ๋ฆฌํ ์ ์์ด. ์ฒ์์ ์ด๋ ค์ ๋ณด์ผ ์ ์์ง๋ง, ํ ๋ฒ ์ต์ํด์ง๋ฉด ์ ๋ง ๊ฐ๋ ฅํ ๋๊ตฌ๊ฐ ๋ผ! ๐ช
โก์ฑ๋ฅ ์ต์ ํ์ ํ์ ์์ ์ฑ
Gatsby์ ํฐ ์ฅ์ ์ค ํ๋๊ฐ ๋ฐ๋ก ์ฑ๋ฅ์ด์ผ. ๊ทธ๋ฐ๋ฐ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๋ฉด์๋ ์ด ์ฑ๋ฅ์ ์ต๋ํ ํ์ฉํ๋ ค๋ฉด ๋ช ๊ฐ์ง ์ต์ ํ ๊ธฐ๋ฒ์ ์์์ผ ํด. ํ์ ์์ ์ฑ๊ณผ ์ฑ๋ฅ, ๋ ๋ง๋ฆฌ ํ ๋ผ๋ฅผ ๋ชจ๋ ์ก๋ ๋ฐฉ๋ฒ์ ์์๋ณด์!
์ฒซ ๋ฒ์งธ๋ ์ด๋ฏธ์ง ์ต์ ํ์ผ. Gatsby๋ gatsby-plugin-image๋ฅผ ํตํด ๊ฐ๋ ฅํ ์ด๋ฏธ์ง ์ต์ ํ๋ฅผ ์ ๊ณตํด. ์ด๊ฑธ ํ์
์์ ํ๊ฒ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ณด์:
import React from 'react';
import { graphql } from 'gatsby';
import { GatsbyImage, getImage, IGatsbyImageData } from 'gatsby-plugin-image';
interface ImageData {
childImageSharp: {
gatsbyImageData: IGatsbyImageData;
};
}
interface PostWithImageQuery {
markdownRemark: {
frontmatter: {
title: string;
featuredImage: ImageData;
};
};
}
export const query = graphql`
query PostWithImage($id: String!) {
markdownRemark(id: { eq: $id }) {
frontmatter {
title
featuredImage {
childImageSharp {
gatsbyImageData(
width: 800
placeholder: BLURRED
formats: [AUTO, WEBP, AVIF]
)
}
}
}
}
}
`;
const PostWithImage: React.FC<{ data: PostWithImageQuery }> = ({ data }) => {
const image = getImage(data.markdownRemark.frontmatter.featuredImage);
return (
<article>
<h1>{data.markdownRemark.frontmatter.title}</h1>
{image && (
<GatsbyImage
image={image}
alt={data.markdownRemark.frontmatter.title}
/>
)}
</article>
);
};
IGatsbyImageData ํ์
์ ์ฌ์ฉํ๋ฉด ์ด๋ฏธ์ง ๋ฐ์ดํฐ์ ๊ตฌ์กฐ๊ฐ ํ์
์์ ํด์ ธ. getImage ํจ์๋ ํ์
๊ฐ๋ ์ญํ ์ ํด์ ์์ ํ๊ฒ ์ด๋ฏธ์ง๋ฅผ ๋ ๋๋งํ ์ ์์ด.
๐จ ์ด๋ฏธ์ง ์ต์ ํ์ ๋ง๋ฒ
Gatsby์ ์ด๋ฏธ์ง ์ต์ ํ๋ ์ ๋ง ๊ฐ๋ ฅํด. ์๋์ผ๋ก ์ฌ๋ฌ ํฌ๊ธฐ์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ , WebP๋ AVIF ๊ฐ์ ์ต์ ํฌ๋งท์ผ๋ก ๋ณํํ๊ณ , lazy loading์ ์ ์ฉํ๊ณ , blur-up ํจ๊ณผ๊น์ง ์ ๊ณตํด. ์ด ๋ชจ๋ ๊ฒ ํ์ ์์ ํ๊ฒ ์๋ํ๋ ์ ๋ง ์๋ฒฝํ์ง?
๋ ๋ฒ์งธ๋ ์ฝ๋ ์คํ๋ฆฌํ ์ด์ผ. Gatsby๋ ์๋์ผ๋ก ํ์ด์ง๋ณ ์ฝ๋ ์คํ๋ฆฌํ ์ ํด์ฃผ์ง๋ง, ์ปดํฌ๋ํธ ๋ ๋ฒจ์์๋ ์ต์ ํํ ์ ์์ด:
import React, { lazy, Suspense } from 'react';
import type { ComponentType } from 'react';
// ํ์
์์ ํ ๋์ import
const HeavyComponent = lazy(() =>
import('./HeavyComponent').then(module => ({
default: module.HeavyComponent
}))
);
interface HeavyComponentProps {
data: string;
onComplete: () => void;
}
const PageWithLazyLoading: React.FC = () => {
return (
<div>
<h1>๋ฉ์ธ ์ฝํ
์ธ </h1>
<Suspense fallback={<div>๋ก๋ฉ ์ค...</div>}>
<HeavyComponent
data="test"
onComplete={() => console.log('์๋ฃ')}
/>
</Suspense>
</div>
);
};
lazy์ Suspense๋ฅผ ์ฌ์ฉํ๋ฉด ํ์ํ ๋๋ง ์ปดํฌ๋ํธ๋ฅผ ๋ก๋ํ ์ ์์ด. ํ์
์คํฌ๋ฆฝํธ์ ํจ๊ป ์ฌ์ฉํ๋ฉด ๋์ ์ผ๋ก ๋ก๋๋๋ ์ปดํฌ๋ํธ์ props๋ ํ์
์ฒดํฌ๊ฐ ๋ผ!
์ธ ๋ฒ์งธ๋ GraphQL ์ฟผ๋ฆฌ ์ต์ ํ์ผ. ํ์ํ ํ๋๋ง ์ ํํ ์์ฒญํ๋ ๊ฒ ์ค์ํด:
// โ ๋์ ์: ๋ถํ์ํ ๋ฐ์ดํฐ๊น์ง ๊ฐ์ ธ์ด
export const query = graphql`
query AllPosts {
allMarkdownRemark {
nodes {
html # ๋ชฉ๋ก ํ์ด์ง์์๋ ํ์ ์์!
frontmatter {
title
date
excerpt
}
}
}
}
`;
// โ
์ข์ ์: ํ์ํ ํ๋๋ง ์์ฒญ
export const query = graphql`
query AllPosts {
allMarkdownRemark {
nodes {
id
excerpt(pruneLength: 160)
frontmatter {
title
date(formatString: "YYYY-MM-DD")
}
}
}
}
`;
GraphQL์ ์ฅ์ ์ ํ์ํ ๋ฐ์ดํฐ๋ง ์ ํํ ์์ฒญํ ์ ์๋ค๋ ๊ฑฐ์ผ. ๋ชฉ๋ก ํ์ด์ง์์ ์ ์ฒด HTML ์ฝํ ์ธ ๋ฅผ ๊ฐ์ ธ์ฌ ํ์๋ ์์์? ์ด๋ ๊ฒ ์ต์ ํํ๋ฉด ๋น๋ ์๊ฐ๋ ์ค๊ณ ๋ฒ๋ค ํฌ๊ธฐ๋ ์์์ ธ. ๐
๐ก ํ๋ก๋์ ๋น๋ ์ต์ ํ
ํ๋ก๋์
๋น๋๋ฅผ ํ ๋๋ gatsby build ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํด. ์ด๋ ํ์
์คํฌ๋ฆฝํธ ์ปดํ์ผ๋ ํจ๊ป ์ผ์ด๋๋๋ฐ, tsconfig.json์์ skipLibCheck: true๋ฅผ ์ค์ ํ๋ฉด ๋น๋ ์๊ฐ์ ํฌ๊ฒ ์ค์ผ ์ ์์ด. ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํ์
์ ์ ํ์ผ์ ์ฒดํฌํ์ง ์์๋ ๋๋๊น!
๐งชํ ์คํ : ํ์ ์์ ํ ํ ์คํธ ์์ฑํ๊ธฐ
ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๋ ํฐ ์ด์ ์ค ํ๋๊ฐ ๋ฐ๋ก ํ ์คํธ ๊ฐ๋ฅ์ฑ์ด์ผ. ํ์ ์์คํ ์ด ๋ง์ ๋ฒ๊ทธ๋ฅผ ์ปดํ์ผ ํ์์ ์ก์์ฃผ์ง๋ง, ๊ทธ๋๋ ํ ์คํธ๋ ํ์์ผ. Gatsby ํ๋ก์ ํธ์์ ํ์ ์์ ํ ํ ์คํธ๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์.
๋จผ์ ํ์ํ ํ ์คํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ์ค์นํ์:
npm install --save-dev @testing-library/react @testing-library/jest-dom @testing-library/user-event jest @types/jest ts-jest
jest.config.js๋ฅผ ์ค์ ํด:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testMatch: [
'**/__tests__/**/*.ts?(x)',
'**/?(*.)+(spec|test).ts?(x)',
],
};
์ด์ ์ปดํฌ๋ํธ ํ ์คํธ๋ฅผ ์์ฑํด๋ณด์. ํ์ ์์ ์ฑ์ ์ ์งํ๋ฉด์ ํ ์คํธํ๋ ๊ฒ ํต์ฌ์ด์ผ:
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { BlogPostCard } from '../components/BlogPostCard';
// ํ
์คํธ์ฉ ํ์
์์ ํ ๋ชฉ ๋ฐ์ดํฐ
const mockPost: BlogPost = {
id: '1',
title: 'ํ
์คํธ ํฌ์คํธ',
excerpt: '์ด๊ฒ์ ํ
์คํธ ํฌ์คํธ์
๋๋ค.',
date: '2024-01-15',
slug: 'test-post',
};
describe('BlogPostCard', () => {
it('ํฌ์คํธ ์ ๋ชฉ์ ๋ ๋๋งํ๋ค', () => {
render(<BlogPostCard post={mockPost} />);
const title = screen.getByRole('heading', {
name: mockPost.title
});
expect(title).toBeInTheDocument();
});
it('ํฌ์คํธ ๋ ์ง๋ฅผ ์ฌ๋ฐ๋ฅธ ํ์์ผ๋ก ํ์ํ๋ค', () => {
render(<BlogPostCard post={mockPost} />);
const date = screen.getByText(/2024๋
1์ 15์ผ/);
expect(date).toBeInTheDocument();
});
it('ํฌ์คํธ ๋งํฌ๊ฐ ์ฌ๋ฐ๋ฅธ ๊ฒฝ๋ก๋ฅผ ๊ฐ์ง๋ค', () => {
render(<BlogPostCard post={mockPost} />);
const link = screen.getByRole('link');
expect(link).toHaveAttribute('href', `/blog/${mockPost.slug}`);
});
});
๋ณด์ด์ง? mockPost๊ฐ BlogPost ํ์
์ผ๋ก ์ ์๋์ด ์์ด์ ํ์
์์ ํด. ๋ง์ฝ ํ์ ํ๋๋ฅผ ๋น ๋จ๋ฆฌ๋ฉด ํ์
์คํฌ๋ฆฝํธ๊ฐ ์ปดํ์ผ ํ์์ ์ค๋ฅ๋ฅผ ๋ฐ์์์ผ.
GraphQL ์ฟผ๋ฆฌ๋ฅผ ํ ์คํธํ ๋๋ ๋ชฉ(mock) ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ ์ผ๋ฐ์ ์ด์ผ:
import { useStaticQuery } from 'gatsby';
import { render, screen } from '@testing-library/react';
import { SiteMetadata } from '../components/SiteMetadata';
import type { SiteMetadataQuery } from '../generated/graphql';
// Gatsby์ useStaticQuery๋ฅผ ๋ชฉํน
jest.mock('gatsby', () => ({
...jest.requireActual('gatsby'),
useStaticQuery: jest.fn(),
}));
describe('SiteMetadata', () => {
const mockData: SiteMetadataQuery = {
site: {
siteMetadata: {
title: 'ํ
์คํธ ์ฌ์ดํธ',
description: 'ํ
์คํธ ์ค๋ช
',
author: 'ํ
์คํธ ์์ฑ์',
},
},
};
beforeEach(() => {
(useStaticQuery as jest.Mock).mockReturnValue(mockData);
});
it('์ฌ์ดํธ ์ ๋ชฉ์ ๋ ๋๋งํ๋ค', () => {
render(<SiteMetadata />);
expect(screen.getByText('ํ
์คํธ ์ฌ์ดํธ')).toBeInTheDocument();
});
});
๐ฏ ํ์ ์์ ํ ๋ชฉ ๋ฐ์ดํฐ์ ์ค์์ฑ
ํ ์คํธ์์ ๋ชฉ ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค ๋๋ ์ค์ ํ์ ์ ์ฌ์ฉํ๋ ๊ฒ ์ค์ํด. GraphQL Code Generator๋ก ์์ฑ๋ ํ์ ์ ์ฌ์ฉํ๋ฉด ์ค์ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ์ ๋์ผํ ๊ตฌ์กฐ์ ๋ชฉ ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค ์ ์์ด. ์ด๋ ๊ฒ ํ๋ฉด ํ ์คํธ๊ฐ ์ค์ ์ฝ๋์ ๋๊ธฐํ๋์ด ์๋ค๋ ๊ฑธ ๋ณด์ฅํ ์ ์์ง!
ํตํฉ ํ ์คํธ๋ ์์ฑํด๋ณด์. Gatsby์ ๋น๋ ํ๋ก์ธ์ค๋ฅผ ํ ์คํธํ๋ ๊ฑด ๋ณต์กํ ์ ์์ง๋ง, ์ค์ํ ๋ถ๋ถ๋ค์ ํ ์คํธํ ์ ์์ด:
import { createPage } from '../gatsby-node';
import type { CreatePagesArgs } from 'gatsby';
describe('gatsby-node', () => {
it('๋ธ๋ก๊ทธ ํฌ์คํธ ํ์ด์ง๋ฅผ ์์ฑํ๋ค', async () => {
const mockGraphql = jest.fn().mockResolvedValue({
data: {
allMarkdownRemark: {
nodes: [
{ id: '1', frontmatter: { slug: 'first-post' } },
{ id: '2', frontmatter: { slug: 'second-post' } },
],
},
},
});
const mockActions = {
createPage: jest.fn(),
};
const args = {
graphql: mockGraphql,
actions: mockActions,
} as unknown as CreatePagesArgs;
await createPage(args);
expect(mockActions.createPage).toHaveBeenCalledTimes(2);
expect(mockActions.createPage).toHaveBeenCalledWith(
expect.objectContaining({
path: '/blog/first-post',
})
);
});
});
์ด๋ ๊ฒ ํ์ ์์ ํ ํ ์คํธ๋ฅผ ์์ฑํ๋ฉด ๋ฆฌํฉํ ๋งํ ๋๋ ์์ ๊ฐ์ ๊ฐ์ง ์ ์์ด. ํ์ ์ด ๋ฐ๋๋ฉด ํ ์คํธ๋ ํจ๊ป ์ ๋ฐ์ดํธํด์ผ ํ๋ค๋ ๊ฑธ ํ์ ์คํฌ๋ฆฝํธ๊ฐ ์๋ ค์ฃผ๋๊น! ๐ช
๐์ค์ ํ๋ก์ ํธ: ํฌํธํด๋ฆฌ์ค ์ฌ์ดํธ ๋ง๋ค๊ธฐ
์ด์ ๋ฐฐ์ด ๋ด์ฉ์ ๋ชจ๋ ํ์ฉํด์ ์ค์ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด๋ณด์. ๊ฐ๋ฐ์ ํฌํธํด๋ฆฌ์ค ์ฌ์ดํธ๋ฅผ ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ก ๊ตฌ์ถํ๋ ๊ฑฐ์ผ. ์ด ๊ณผ์ ์์ ํ์ ์์ ํ GraphQL ์ฟผ๋ฆฌ, ์ปดํฌ๋ํธ ์ค๊ณ, ์ฑ๋ฅ ์ต์ ํ๊น์ง ๋ชจ๋ ๊ฑธ ๋ค๋ค๋ณผ ๊ฑฐ์ผ.
๋จผ์ ํ๋ก์ ํธ์ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ฅผ ์ค๊ณํ์. ํฌํธํด๋ฆฌ์ค ์ฌ์ดํธ์๋ ์ด๋ฐ ๋ฐ์ดํฐ๊ฐ ํ์ํด:
// src/types/index.ts
export interface Project {
id: string;
title: string;
description: string;
technologies: string[];
githubUrl?: string;
liveUrl?: string;
thumbnail: ImageData;
featured: boolean;
date: string;
}
export interface Experience {
id: string;
company: string;
position: string;
startDate: string;
endDate?: string;
description: string;
technologies: string[];
}
export interface Skill {
name: string;
level: number; // 1-5
category: 'frontend' | 'backend' | 'devops' | 'other';
}
export interface SiteMetadata {
title: string;
description: string;
author: {
name: string;
email: string;
github: string;
linkedin: string;
};
}
์ด์ ์ด ๋ฐ์ดํฐ๋ค์ ๋งํฌ๋ค์ด ํ์ผ๋ก ๊ด๋ฆฌํ์. content/projects/awesome-project.md:
---
title: "๋ฉ์ง ํ๋ก์ ํธ"
description: "ํ์
์คํฌ๋ฆฝํธ์ React๋ก ๋ง๋ ์น ์ ํ๋ฆฌ์ผ์ด์
"
technologies: ["TypeScript", "React", "Gatsby", "GraphQL"]
githubUrl: "https://github.com/username/awesome-project"
liveUrl: "https://awesome-project.com"
featured: true
date: "2024-01-15"
thumbnail: "./images/project-thumbnail.png"
---
## ํ๋ก์ ํธ ๊ฐ์
์ด ํ๋ก์ ํธ๋ ํ์
์คํฌ๋ฆฝํธ์ React๋ฅผ ํ์ฉํ ํ๋์ ์ธ ์น ์ ํ๋ฆฌ์ผ์ด์
์
๋๋ค.
## ์ฃผ์ ๊ธฐ๋ฅ
- ํ์
์์ ํ ์ํ ๊ด๋ฆฌ
- GraphQL์ ํตํ ํจ์จ์ ์ธ ๋ฐ์ดํฐ ํ์นญ
- ๋ฐ์ํ ๋์์ธ
- ์ฑ๋ฅ ์ต์ ํ
GraphQL ์คํค๋ง๋ฅผ ์ ์ํ๊ณ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ์. src/pages/index.tsx:
import React from 'react';
import { graphql, PageProps } from 'gatsby';
import { GatsbyImage, getImage } from 'gatsby-plugin-image';
import type { HomePageQuery } from '../generated/graphql';
export const query = graphql`
query HomePage {
site {
siteMetadata {
title
description
author {
name
email
github
linkedin
}
}
}
featuredProjects: allMarkdownRemark(
filter: {
fileAbsolutePath: { regex: "/projects/" }
frontmatter: { featured: { eq: true } }
}
sort: { frontmatter: { date: DESC } }
limit: 3
) {
nodes {
id
frontmatter {
title
description
technologies
githubUrl
liveUrl
thumbnail {
childImageSharp {
gatsbyImageData(
width: 400
placeholder: BLURRED
)
}
}
}
fields {
slug
}
}
}
skills: allSkillsYaml {
nodes {
name
level
category
}
}
}
`;
const HomePage: React.FC<PageProps<HomePageQuery>> = ({ data }) => {
const { site, featuredProjects, skills } = data;
const metadata = site?.siteMetadata;
return (
<main>
{/* Hero Section */}
<section>
<h1>์๋
ํ์ธ์, {metadata?.author?.name}์
๋๋ค</h1>
<p>{metadata?.description}</p>
<div>
<a href={`mailto:${metadata?.author?.email}`}>์ด๋ฉ์ผ</a>
<a href={metadata?.author?.github}>GitHub</a>
<a href={metadata?.author?.linkedin}>LinkedIn</a>
</div>
</section>
{/* Featured Projects */}
<section>
<h2>์ฃผ์ ํ๋ก์ ํธ</h2>
<div>
{featuredProjects.nodes.map(project => {
const image = getImage(project.frontmatter?.thumbnail);
return (
<article key={project.id}>
{image && (
<GatsbyImage
image={image}
alt={project.frontmatter?.title || ''}
/>
)}
<h3>{project.frontmatter?.title}</h3>
<p>{project.frontmatter?.description}</p>
<div>
{project.frontmatter?.technologies?.map(tech => (
<span key={tech}>{tech}</span>
))}
</div>
<div>
{project.frontmatter?.githubUrl && (
<a href={project.frontmatter.githubUrl}>GitHub</a>
)}
{project.frontmatter?.liveUrl && (
<a href={project.frontmatter.liveUrl}>Live Demo</a>
)}
</div>
</article>
);
})}
</div>
</section>
{/* Skills */}
<section>
<h2>๊ธฐ์ ์คํ</h2>
<div>
{['frontend', 'backend', 'devops', 'other'].map(category => {
const categorySkills = skills.nodes.filter(
skill => skill.category === category
);
if (categorySkills.length === 0) return null;
return (
<div key={category}>
<h3>{category.toUpperCase()}</h3>
{categorySkills.map(skill => (
<div key={skill.name}>
<span>{skill.name}</span>
<div>
<div style={{ width: `${skill.level * 20}%` }} />
</div>
</div>
))}
</div>
);
})}
</div>
</section>
</main>
);
};
export default HomePage;
์๋ฒฝํ์ง? ๋ชจ๋ ๋ฐ์ดํฐ๊ฐ ํ์
์์ ํ๊ฒ ์ฒ๋ฆฌ๋๊ณ ์์ด. data ๊ฐ์ฒด์ ๋ชจ๋ ํ๋์ ์๋์์ฑ์ด ์๋ํ๊ณ , ์๋ชป๋ ํ๋์ ์ ๊ทผํ๋ ค๊ณ ํ๋ฉด ์ปดํ์ผ ์ค๋ฅ๊ฐ ๋ฐ์ํด.
โจ ์ฌ๋ฅ๋ท์์ ํฌํธํด๋ฆฌ์ค ๊ณต์ ํ๊ธฐ
์ด๋ ๊ฒ ๋ง๋ ํฌํธํด๋ฆฌ์ค๋ฅผ ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ๊ณต์ ํ๋ฉด ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค๊ณผ ์ง์์ ๋๋๊ณ ํผ๋๋ฐฑ์ ๋ฐ์ ์ ์์ด. ํนํ ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ฅผ ํ์ฉํ ์ค์ ์์ ๋ ๋ง์ ์ฌ๋๋ค์๊ฒ ๋์์ด ๋ ๊ฑฐ์ผ!
์ด์ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค์ด๋ณด์. src/components/ProjectCard.tsx:
import React from 'react';
import { Link } from 'gatsby';
import { GatsbyImage, getImage, IGatsbyImageData } from 'gatsby-plugin-image';
interface ProjectCardProps {
project: {
id: string;
frontmatter: {
title: string;
description: string;
technologies: string[];
githubUrl?: string;
liveUrl?: string;
thumbnail: {
childImageSharp: {
gatsbyImageData: IGatsbyImageData;
};
};
};
fields: {
slug: string;
};
};
featured?: boolean;
}
export const ProjectCard: React.FC<ProjectCardProps> = ({
project,
featured = false
}) => {
const image = getImage(project.frontmatter.thumbnail);
return (
<article className={featured ? 'featured-project' : 'project-card'}>
<Link to={project.fields.slug}>
{image && (
<GatsbyImage
image={image}
alt={project.frontmatter.title}
/>
)}
</Link>
<div>
<h3>
<Link to={project.fields.slug}>
{project.frontmatter.title}
</Link>
</h3>
<p>{project.frontmatter.description}</p>
<div>
{project.frontmatter.technologies.map(tech => (
<span key={tech} className="tech-tag">
{tech}
</span>
))}
</div>
<div>
{project.frontmatter.githubUrl && (
<a
href={project.frontmatter.githubUrl}
target="_blank"
rel="noopener noreferrer"
>
GitHub
</a>
)}
{project.frontmatter.liveUrl && (
<a
href={project.frontmatter.liveUrl}
target="_blank"
rel="noopener noreferrer"
>
Live Demo
</a>
)}
</div>
</div>
</article>
);
};
์ด ์ปดํฌ๋ํธ๋ ์์ ํ ํ์
์์ ํด. ProjectCardProps ์ธํฐํ์ด์ค๊ฐ ๋ชจ๋ prop์ ๊ตฌ์กฐ๋ฅผ ๋ช
ํํ ์ ์ํ๊ณ ์์ด์, ์ด ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํ๋ ๊ณณ์์ ์๋ชป๋ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ๋ฉด ์ฆ์ ์ค๋ฅ๊ฐ ๋ฐ์ํด. ๐ฏ
๐๋ฐฐํฌ์ CI/CD
ํ๋ก์ ํธ๋ฅผ ์์ฑํ์ผ๋ฉด ์ด์ ๋ฐฐํฌํ ์ฐจ๋ก์ผ. Gatsby ์ฌ์ดํธ๋ฅผ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ ์ ๋ง ๋ค์ํด. Netlify, Vercel, GitHub Pages, AWS S3 ๋ฑ๋ฑ. ์ฌ๊ธฐ์๋ ๊ฐ์ฅ ์ธ๊ธฐ ์๋ Netlify๋ฅผ ์ฌ์ฉํด๋ณด์.
๋จผ์ netlify.toml ํ์ผ์ ๋ง๋ค์ด:
[build]
command = "npm run build"
publish = "public"
[build.environment]
NODE_VERSION = "18"
[[plugins]]
package = "netlify-plugin-gatsby-cache"
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-XSS-Protection = "1; mode=block"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "strict-origin-when-cross-origin"
[[headers]]
for = "/*.js"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/*.css"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
์ด ์ค์ ํ์ผ์ ๋น๋ ๋ช ๋ น์ด, ๋ฐฐํฌ ๋๋ ํ ๋ฆฌ, ์บ์ฑ ์ ๋ต, ๋ณด์ ํค๋ ๋ฑ์ ์ ์ํด. ํนํ ์ ์ ํ์ผ๋ค์ ๋ํ ์บ์ฑ ์ค์ ์ด ์ค์ํด. ์๋ฐ์คํฌ๋ฆฝํธ์ CSS ํ์ผ์ 1๋ ๋์ ์บ์๋๋๋ก ์ค์ ํ์ด.
โก ๋น๋ ์ต์ ํ ํ
Gatsby ๋น๋๋ ํ๋ก์ ํธ ํฌ๊ธฐ์ ๋ฐ๋ผ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆด ์ ์์ด. netlify-plugin-gatsby-cache ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๋ฉด ๋น๋ ์บ์๋ฅผ ํ์ฉํด์ ๋น๋ ์๊ฐ์ ํฌ๊ฒ ์ค์ผ ์ ์์ด. ํนํ ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๊ฐ์ ๋ฌด๊ฑฐ์ด ์์
์ด ๋ง์ ๋ ํจ๊ณผ์ ์ด์ผ!
GitHub Actions๋ฅผ ์ฌ์ฉํด์ CI/CD ํ์ดํ๋ผ์ธ์ ๊ตฌ์ถํ ์๋ ์์ด. .github/workflows/ci.yml:
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Type check
run: npm run type-check
- name: Lint
run: npm run lint
- name: Test
run: npm run test
- name: Build
run: npm run build
env:
NODE_ENV: production
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Deploy to Netlify
uses: netlify/actions/cli@master
with:
args: deploy --prod
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
์ด ์ํฌํ๋ก์ฐ๋ ์ฝ๋๊ฐ ํธ์๋ ๋๋ง๋ค ์๋์ผ๋ก ์คํ๋ผ. ํ์ ์ฒดํฌ, ๋ฆฐํธ, ํ ์คํธ, ๋น๋๋ฅผ ์์๋๋ก ์คํํ๊ณ , ๋ชจ๋ ๊ฒ ์ฑ๊ณตํ๋ฉด main ๋ธ๋์น์ ๊ฒฝ์ฐ ์๋์ผ๋ก ๋ฐฐํฌ๊น์ง ํด์ค. ์ ๋ง ํธ๋ฆฌํ์ง? ๐
ํ์
์คํฌ๋ฆฝํธ ํ๋ก์ ํธ์์๋ type-check ์คํฌ๋ฆฝํธ๋ฅผ package.json์ ์ถ๊ฐํ๋ ๊ฒ ์ข์:
{
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean",
"type-check": "tsc --noEmit",
"lint": "eslint . --ext .ts,.tsx",
"test": "jest",
"codegen": "graphql-codegen"
}
}
tsc --noEmit ๋ช
๋ น์ด๋ ์ค์ ๋ก ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์ ์์ฑํ์ง ์๊ณ ํ์
์ฒดํฌ๋ง ์ํํด. CI/CD ํ์ดํ๋ผ์ธ์์ ํ์
์ค๋ฅ๋ฅผ ๋น ๋ฅด๊ฒ ์ก์ ์ ์์ด.
๐๋๋ฒ๊น ๊ณผ ๋ฌธ์ ํด๊ฒฐ
์๋ฌด๋ฆฌ ํ์ ์์ ํ ์ฝ๋๋ฅผ ์์ฑํด๋ ๋ฌธ์ ๋ ์๊ธฐ๊ธฐ ๋ง๋ จ์ด์ผ. Gatsby์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ํจ๊ป ์ฌ์ฉํ ๋ ์์ฃผ ๋ง์ฃผ์น๋ ๋ฌธ์ ๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์์๋ณด์.
โ GraphQL ํ์ ๋ถ์ผ์น
๋ฌธ์ : GraphQL ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ์ ์์ฑ๋ ํ์ ์ด ๋ง์ง ์์
ํด๊ฒฐ:
// 1. ๊ฐ๋ฐ ์๋ฒ ์ฌ์์
gatsby clean
gatsby develop
// 2. ์ฝ๋ ์์ฑ ๋ค์ ์คํ
npm run codegen
// 3. IDE ์ฌ์์
GraphQL ์คํค๋ง๊ฐ ๋ณ๊ฒฝ๋๋ฉด ๋ฐ๋์ ์ฝ๋ ์์ฑ์ ๋ค์ ์คํํด์ผ ํด!
โ ๏ธ ๋น๋ ํ์ ์ค๋ฅ
๋ฌธ์ : ๊ฐ๋ฐ ํ๊ฒฝ์์๋ ์ ๋๋๋ฐ ๋น๋ํ ๋ ์ค๋ฅ ๋ฐ์
ํด๊ฒฐ:
// tsconfig.json ํ์ธ
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true
}
}
// ๋ชจ๋ null ์ฒดํฌ ์ถ๊ฐ
const title = post?.frontmatter?.title ?? '์ ๋ชฉ ์์';
ํ๋ก๋์ ๋น๋๋ ๋ ์๊ฒฉํ ์ฒดํฌ๋ฅผ ํ๋๊น null ์ฒดํฌ๋ฅผ ๊ผผ๊ผผํ ํด์ผ ํด!
GraphQL ์ฟผ๋ฆฌ ๋๋ฒ๊น
์ ์ํด์๋ Gatsby์ GraphiQL์ ํ์ฉํ์. ๊ฐ๋ฐ ์๋ฒ๋ฅผ ์คํํ๊ณ http://localhost:8000/___graphql์ ์ ์ํ๋ฉด ์ธํฐ๋ํฐ๋ธํ GraphQL ํ๋ ์ด๊ทธ๋ผ์ด๋๋ฅผ ์ฌ์ฉํ ์ ์์ด:
// GraphiQL์์ ์ฟผ๋ฆฌ ํ
์คํธ
{
allMarkdownRemark {
nodes {
frontmatter {
title
date
}
}
}
}
// ๊ฒฐ๊ณผ ํ์ธ ํ ์ปดํฌ๋ํธ์ ๋ณต์ฌ
export const query = graphql`
query {
allMarkdownRemark {
nodes {
frontmatter {
title
date
}
}
}
}
`;
๐ง VSCode ํ์ฅ ํ๋ก๊ทธ๋จ ์ถ์ฒ
ํ์
์คํฌ๋ฆฝํธ์ Gatsby ๊ฐ๋ฐ์ ๋ ํธํ๊ฒ ํด์ฃผ๋ VSCode ํ์ฅ ํ๋ก๊ทธ๋จ๋ค์ด ์์ด:
- GraphQL: GraphQL ์ฟผ๋ฆฌ ํ์ด๋ผ์ดํ
๊ณผ ์๋์์ฑ
- Prettier: ์ฝ๋ ํฌ๋งทํ
- ESLint: ์ฝ๋ ํ์ง ์ฒดํฌ
- Error Lens: ์ธ๋ผ์ธ ์ค๋ฅ ํ์
- TypeScript Error Translator: ํ์
์ค๋ฅ๋ฅผ ์ดํดํ๊ธฐ ์ฝ๊ฒ ๋ฒ์ญ
ํ์ ์ค๋ฅ๊ฐ ์ดํดํ๊ธฐ ์ด๋ ค์ธ ๋๋ ๋จ๊ณ๋ณ๋ก ์ ๊ทผํ์:
// ๋ณต์กํ ํ์
์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด
// 1. ํ์
์ ๋ช
์์ ์ผ๋ก ์ ์ธ
const posts: Array<MarkdownRemarkNode> = data.allMarkdownRemark.nodes;
// 2. ์ค๊ฐ ๋ณ์๋ก ๋ถ๋ฆฌ
const frontmatter = post.frontmatter;
const title = frontmatter?.title;
// 3. ํ์
๊ฐ๋ ์ฌ์ฉ
if (isValidPost(post)) {
// ์ด ๋ธ๋ก ์์์๋ post๊ฐ ํ์คํ ์ ํจํจ
console.log(post.title);
}
// 4. ํ์
๋จ์ธ์ ์ตํ์ ์๋จ
const title = (post.frontmatter as NonNullable<Frontmatter>).title;
ํ์
๋จ์ธ(as)์ ํ์
์คํฌ๋ฆฝํธ์ ํ์
์ฒดํฌ๋ฅผ ์ฐํํ๋ ๊ฑฐ๋ผ์ ๊ฐ๋ฅํ ํ ํผํ๋ ๊ฒ ์ข์. ๋์ ํ์
๊ฐ๋๋ null ์ฒดํฌ๋ฅผ ์ฌ์ฉํ์!
๐๋ ๋์๊ฐ๊ธฐ: ๊ณ ๊ธ ํจํด๊ณผ ์ต์ ํ
๊ธฐ๋ณธ์ ๋ง์คํฐํ๋ค๋ฉด ์ด์ ๊ณ ๊ธ ํจํด๋ค์ ๋ฐฐ์ธ ์ฐจ๋ก์ผ. ์ค์ ํ๋ก๋์ ํ๊ฒฝ์์ ์ฌ์ฉ๋๋ ํจํด๋ค์ ์์๋ณด์.
์ฒซ ๋ฒ์งธ๋ ํ์ ์์ ํ ํ๊ฒฝ ๋ณ์ ๊ด๋ฆฌ์ผ. ํ๊ฒฝ ๋ณ์๋ฅผ ํ์ ์์ ํ๊ฒ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ:
// src/types/env.d.ts
declare namespace NodeJS {
interface ProcessEnv {
readonly GATSBY_API_URL: string;
readonly GATSBY_SITE_URL: string;
readonly CONTENTFUL_SPACE_ID: string;
readonly CONTENTFUL_ACCESS_TOKEN: string;
}
}
// src/utils/env.ts
export const env = {
apiUrl: process.env.GATSBY_API_URL,
siteUrl: process.env.GATSBY_SITE_URL,
contentful: {
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
},
} as const;
// ํ์
์ฒดํฌ์ ํจ๊ป ์ฌ์ฉ
if (!env.apiUrl) {
throw new Error('GATSBY_API_URL is not defined');
}
// ์ด์ env.apiUrl์ string ํ์
์ผ๋ก ๋ณด์ฅ๋จ
fetch(env.apiUrl);
๋ ๋ฒ์งธ๋ ์ปค์คํ ํ ๊ณผ ํ์ ์์ ์ฑ์ด์ผ. GraphQL ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ ์ปค์คํ ํ ์ ๋ง๋ค์ด๋ณด์:
import { useStaticQuery, graphql } from 'gatsby';
import type { SiteMetadataQuery } from '../generated/graphql';
export function useSiteMetadata() {
const data = useStaticQuery<SiteMetadataQuery>(graphql`
query SiteMetadata {
site {
siteMetadata {
title
description
author {
name
email
}
}
}
}
`);
return data.site?.siteMetadata;
}
// ์ฌ์ฉ
const MyComponent: React.FC = () => {
const metadata = useSiteMetadata();
// metadata์ ํ์
์ด ์๋ฒฝํ๊ฒ ์ถ๋ก ๋จ
return <h1>{metadata?.title}</h1>;
};
์ธ ๋ฒ์งธ๋ ํ์ ์์ ํ ๋ผ์ฐํ ์ด์ผ. ํ์ด์ง ๊ฒฝ๋ก๋ฅผ ํ์ ์์ ํ๊ฒ ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ:
// src/utils/routes.ts
export const routes = {
home: '/',
about: '/about',
blog: {
index: '/blog',
post: (slug: string) => `/blog/${slug}`,
},
projects: {
index: '/projects',
detail: (id: string) => `/projects/${id}`,
},
contact: '/contact',
} as const;
// ์ฌ์ฉ
import { Link } from 'gatsby';
import { routes } from '../utils/routes';
const Navigation: React.FC = () => (
<nav>
<Link to={routes.home}>ํ</Link>
<Link to={routes.about}>์๊ฐ</Link>
<Link to={routes.blog.index}>๋ธ๋ก๊ทธ</Link>
<Link to={routes.projects.index}>ํ๋ก์ ํธ</Link>
</nav>
);
// ๋์ ๋ผ์ฐํธ
const BlogPost: React.FC<{ slug: string }> = ({ slug }) => (
<Link to={routes.blog.post(slug)}>
ํฌ์คํธ ๋ณด๊ธฐ
</Link>
);
์ด๋ ๊ฒ ํ๋ฉด ๋ผ์ฐํธ๋ฅผ ๋ณ๊ฒฝํ ๋ ํ ๊ณณ๋ง ์์ ํ๋ฉด ๋๊ณ , ์๋ชป๋ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํ๋ฉด ํ์ ์ค๋ฅ๊ฐ ๋ฐ์ํด์ ์์ ํด!
์ ๋ค์ด์ด๊ทธ๋จ์ฒ๋ผ ํ์ ์์ ์ฑ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ชจ๋ ๋ ์ด์ด์ ๊ฑธ์ณ ์์ด์ผ ํด. ํ์ ์ ์๋ถํฐ ๋น์ฆ๋์ค ๋ก์ง, UI ์ปดํฌ๋ํธ๊น์ง ์ผ๊ด๋ ํ์ ์์คํ ์ ์ ์งํ๋ ๊ฒ ์ค์ํด!
๐๋ง๋ฌด๋ฆฌํ๋ฉฐ
์, ์ ๋ง ๊ธด ์ฌ์ ์ด์์ง? ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ฅผ ํ์ฉํ ์ ์ ์ฌ์ดํธ ์์ฑ, ๊ทธ๋ฆฌ๊ณ ํ์ ์์ ํ GraphQL์ ๋ํด ์ ๋ง ๋ง์ ๊ฑธ ๋ฐฐ์ ์ด. ์ด์ ํต์ฌ ๋ด์ฉ๋ค์ ์ ๋ฆฌํด๋ณด์.
๐ฏ ํต์ฌ ์์ฝ
1. ์ ์ ์ฌ์ดํธ ์์ฑ์ ์ฅ์
- ๋น ๋ฅธ ์ฑ๋ฅ๊ณผ ๋ฐ์ด๋ SEO
- ์ ๋ ดํ ํธ์คํ
๋น์ฉ
- ๊ฐํ๋ ๋ณด์
2. Gatsby + TypeScript์ ์๋์ง
- GraphQL์ ํตํ ํตํฉ ๋ฐ์ดํฐ ๋ ์ด์ด
- ํ์
์์ ํ ์ปดํฌ๋ํธ ๊ฐ๋ฐ
- ๋ฐ์ด๋ ๊ฐ๋ฐ์ ๊ฒฝํ
3. GraphQL Code Generator
- ์๋ ํ์
์์ฑ์ผ๋ก ์์ฐ์ฑ ํฅ์
- ์ปดํ์ผ ํ์ ์ค๋ฅ ๊ฒ์ถ
- ์๋ฒฝํ IDE ์ง์
4. ์ค์ ํจํด
- ์ ๋ค๋ฆญ๊ณผ ์ ํธ๋ฆฌํฐ ํ์
ํ์ฉ
- ํ์
๊ฐ๋์ null ์ฒดํฌ
- ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ ์ค๊ณ
ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ฅผ ํจ๊ป ์ฌ์ฉํ๋ฉด ์ ๋ง ๊ฐ๋ ฅํ ๊ฐ๋ฐ ํ๊ฒฝ์ ๊ตฌ์ถํ ์ ์์ด. ํ์ ์์ ์ฑ์ ๋จ์ํ ๋ฒ๊ทธ๋ฅผ ์ค์ด๋ ๊ฒ ์ด์์ ์๋ฏธ๊ฐ ์์ด. ์ฝ๋์ ์๋๋ฅผ ๋ช ํํ๊ฒ ์ ๋ฌํ๊ณ , ๋ฆฌํฉํ ๋ง์ ์์ ํ๊ฒ ๋ง๋ค๊ณ , ํ ํ์ ์ ์ํํ๊ฒ ํด์ฃผ์ง.
ํนํ GraphQL๊ณผ์ ์กฐํฉ์ ์ ๋ง ํ์์ ์ด์ผ. ๋ฐ์ดํฐ ์์ค๊ฐ ์ด๋๋ ์๊ด์์ด ์ผ๊ด๋ ๋ฐฉ์์ผ๋ก ์ ๊ทผํ ์ ์๊ณ , ๋ชจ๋ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๊ฐ ํ์ ์์ ํ๊ฒ ์ฒ๋ฆฌ๋ผ. ์ด๊ฑด ๋๊ท๋ชจ ํ๋ก์ ํธ์์ ์ ๋ง ํฐ ๊ฐ์น๋ฅผ ๋ฐํํด.
๋ฌผ๋ก ์ฒ์์๋ ํ์ต ๊ณก์ ์ด ์์ด. ํ์ ์คํฌ๋ฆฝํธ์ ๊ณ ๊ธ ๊ธฐ๋ฅ๋ค, Gatsby์ ๋น๋ ์์คํ , GraphQL์ ๊ฐ๋ ๋ค์ ๋ชจ๋ ์ดํดํด์ผ ํ๋๊น. ํ์ง๋ง ํ ๋ฒ ์ต์ํด์ง๋ฉด ๋ค์ ๋์๊ฐ ์ ์์ ๊ฑฐ์ผ. ํ์ ์์ ์ฑ ์์ด ๊ฐ๋ฐํ๋ ๊ฒ ๋ถ์ํ๊ฒ ๋๊ปด์ง ์ ๋๋ก ๋ง์ด์ผ! ๐
๐ ๋ค์ ๋จ๊ณ๋ก
์ด์ ๋ฐฐ์ด ๋ด์ฉ์ ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํด๋ณด์. ์์ ๋ธ๋ก๊ทธ๋ ํฌํธํด๋ฆฌ์ค ์ฌ์ดํธ๋ถํฐ ์์ํด์ ์ ์ ๋ณต์กํ ํ๋ก์ ํธ๋ก ํ์ฅํด๋๊ฐ๋ฉด ๋ผ. ๊ทธ๋ฆฌ๊ณ ์ปค๋ฎค๋ํฐ์ ์ฐธ์ฌํด์ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค๊ณผ ๊ฒฝํ์ ๊ณต์ ํ๋ ๊ฒ๋ ์์ง ๋ง!
๋ง์ง๋ง์ผ๋ก ํ ๊ฐ์ง ํ์ ์ฃผ์๋ฉด, ์๋ฒฝ์ ์ถ๊ตฌํ์ง ๋ง. ์ฒ์๋ถํฐ ๋ชจ๋ ํ์ ์ ์๋ฒฝํ๊ฒ ์ ์ํ๋ ค๊ณ ํ๋ฉด ์คํ๋ ค ์์ฐ์ฑ์ด ๋จ์ด์ง ์ ์์ด. ๋จผ์ ์๋ํ๋ ์ฝ๋๋ฅผ ๋ง๋ค๊ณ , ์ ์ง์ ์ผ๋ก ํ์ ์์ ์ฑ์ ๋์ฌ๊ฐ๋ ๊ฒ ์ข์ ์ ๊ทผ ๋ฐฉ๋ฒ์ด์ผ.
ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ ๊ณ์ ๋ฐ์ ํ๊ณ ์์ด. ์๋ก์ด ๊ธฐ๋ฅ๋ค์ด ์ถ๊ฐ๋๊ณ , ์ฑ๋ฅ์ด ๊ฐ์ ๋๊ณ , ๊ฐ๋ฐ์ ๊ฒฝํ์ด ํฅ์๋๊ณ ์์ง. ๊ณต์ ๋ฌธ์๋ฅผ ์์ฃผ ํ์ธํ๊ณ , ์ปค๋ฎค๋ํฐ์ ๋ฒ ์คํธ ํ๋ํฐ์ค๋ฅผ ๋ฐ๋ผ๊ฐ๋ ๊ฒ ์ค์ํด.
์ด ๊ธ์ด ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ฅผ ์์ํ๋ ๋ฐ ๋์์ด ๋์์ผ๋ฉด ์ข๊ฒ ์ด. ๊ถ๊ธํ ์ ์ด ์๊ฑฐ๋ ๋ ๊น์ด ์๋ ๋ด์ฉ์ ์๊ณ ์ถ๋ค๋ฉด ๊ณต์ ๋ฌธ์๋ ์ปค๋ฎค๋ํฐ๋ฅผ ํ์ฉํด๋ด. ํนํ Gatsby Discord๋ TypeScript GitHub Discussions๋ ์ ๋ง ํ๋ฐํ ์ปค๋ฎค๋ํฐ์ผ!
์, ์ด์ ์ง์ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด๋ณผ ์๊ฐ์ด์ผ. ๋ฐฐ์ด ๋ด์ฉ์ ์ค์ ์ ์ ์ฉํ๋ฉด์ ์์ ๋ง์ ๋ ธํ์ฐ๋ฅผ ์์๊ฐ๊ธธ ๋ฐ๋ผ. ํ์ ์์ ํ ์ฝ๋ฉ์ ์ธ๊ณ๋ก, ํ์ดํ ! ๐
๐ ์ถ๊ฐ ํ์ต ์๋ฃ
๊ณต์ ๋ฌธ์:
- Gatsby ๊ณต์ ๋ฌธ์: https://www.gatsbyjs.com/docs/
- TypeScript ํธ๋๋ถ: https://www.typescriptlang.org/docs/
- GraphQL ๊ณต์ ์ฌ์ดํธ: https://graphql.org/
์ ์ฉํ ๋๊ตฌ:
- GraphQL Code Generator: https://www.graphql-code-generator.com/
- Gatsby Plugin Library: https://www.gatsbyjs.com/plugins
- TypeScript Playground: https://www.typescriptlang.org/play
์ปค๋ฎค๋ํฐ:
- Gatsby Discord
- TypeScript Community Discord
- Stack Overflow
์ ๋ง ๊ธด ๊ธ์ ๋๊น์ง ์ฝ์ด์ค์ ๊ณ ๋ง์! ํ์ ์คํฌ๋ฆฝํธ์ Gatsby๋ก ๋ฉ์ง ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด๋ณด๊ธธ ๋ฐ๋ผ. ๊ทธ๋ฆฌ๊ณ ๋ง๋ ํ๋ก์ ํธ๋ฅผ ๋ค๋ฅธ ์ฌ๋๋ค๊ณผ ๊ณต์ ํ๋ ๊ฒ๋ ์์ง ๋ง. ์ง์์ ๋๋๋ ๊ฒ์ด์ผ๋ง๋ก ๊ฐ๋ฐ์ ์ปค๋ฎค๋ํฐ๋ฅผ ๋์ฑ ํ์๋กญ๊ฒ ๋ง๋๋ ๋ฐฉ๋ฒ์ด๋๊น! ๐ชโจ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.