Front-End/Next.js

Next.js] ํ”„๋กœ์ ํŠธ ํด๋” ๊ตฌ์กฐ

์™•๊ฐ€๐Ÿ‘ 2023. 8. 15. 22:38
728x90
๋ฐ˜์‘ํ˜•

๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋ฉด ์‚ฌ์ง„๊ณผ ๊ฐ™์€ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ถ”๊ฐ€ ์˜ต์…˜์œผ๋กœ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ์„ค์ •ํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
Next 13 ๋ฒ„์ „๋ถ€ํ„ฐ ์ƒ๊ธด app router๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. (์ด์ „ ๋ฒ„์ „ ๊นŒ์ง€๋Š” ๋ณดํ†ต pages๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ผ์šฐํŒ…์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.)

npx create-next-app@latest

 

 

 

์ด๋ ‡๊ฒŒ ์ƒ์„ฑ๋œ ํด๋” ๊ตฌ์กฐ์—์„œ ์ƒ์„ฑ๋œ ํŒŒ์ผ์„ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 


 

 

 

Layout.tsx

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์„ค์น˜ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— tsxํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ํŒŒ์ผ์€ ๊ธฐ๋ณธ์ ์ด ํ”„๋กœ์ ํŠธ, ์›นํŽ˜์ด์ง€์˜ ๊ณจ๊ฒฉ์ด๋ผ๊ณ  ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

_app์ด๋ž‘ ๋น„์Šทํ•œ๊ฐ€? ์‹ถ์Šต๋‹ˆ๋‹ค.

 

import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'

const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
  title: 'Create Next App',
  description: 'Generated by create next app',
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    </html>
  )
}

 

 

 

 

 

 

 

page.tsx

layout ํŒŒ์ผ์„ ๋ณด๋ฉด body์•ˆ์— children ์ด ๋ถ€๋ถ„์ด ์ด์ œ page.tsx์˜ return ๊ฐ’๋“ค์ด ๋“ค์–ด๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ด์ „์— _documentํŒŒ์ผ?์ด๋ผ๊ณ  ๋ณด์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

import Image from 'next/image'
import styles from './page.module.css'

export default function Home() {
  return (
    <main className={styles.main}>
      <div className={styles.description}>
        ...
      </div>
    </main>
  )
}

 

 

 


 

 

 

global.css 

ํ”„๋กœ์ ํŠธ ์ „์ฒด์˜ ์ „์—ญ cssํŒŒ์ผ์ด๋ผ๊ณ  ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. css์ดˆ๊ธฐ ์„ธํŒ…? ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

 

 


 

 

 

๊ทธ ์™ธ ํŒŒ์ผ

  • next.config.js : next ์„ค์ •ํŒŒ์ผ
  • package.json : ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
  • middleware.ts : ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ ์ค‘๊ฐ„์— ๊ฑฐ์น˜๋Š” ๋‹จ๊ณ„(?)
  • .env : ํ™˜๊ฒฝ๋ณ€์ˆ˜์„ค์ • ๊ด€๋ จ ํŒŒ์ผ (.env.local, .env.development, .env.production)

 

 

728x90

'Front-End > Next.js' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Next.js] Next.js ์„ค์น˜ ๋ฐ ์‹œ์ž‘, ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ (Insallation)  (0) 2023.08.09
Next.js] Next.js๋ž€?  (0) 2023.08.06