Syw.Frontend

๐Ÿ“˜ Next.js ๊ธฐ์ดˆ ๊ฐ•์ขŒ

1๋‹จ๊ณ„. Next.js ์ž…๋ฌธ (๊ฐœ๋… & ํ™œ์šฉ ๊ธฐ์ดˆ)

1-4. ์Šคํƒ€์ผ๋ง๊ณผ ๋ ˆ์ด์•„์›ƒ

1. Next.js ์Šคํƒ€์ผ๋ง ๋ฐฉ๋ฒ•

Next.js์—์„œ๋Š” ๋Œ€ํ‘œ์ ์œผ๋กœ 3๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ์Šคํƒ€์ผ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ์ „์—ญ ์Šคํƒ€์ผ (globals.css / SCSS ๊ฐ€๋Šฅ)

    โ†’ ๋ชจ๋“  ํŽ˜์ด์ง€์— ๊ณตํ†ต ์ ์šฉ

  2. CSS Module / SCSS Module (.module.scss)

    โ†’ ์ปดํฌ๋„ŒํŠธ ๋‹จ์œ„๋กœ ์Šคํƒ€์ผ ์บก์Аํ™”

  3. CSS-in-JS (styled-components, emotion ๋“ฑ)

    โ†’ ์ด๋ฒˆ ๊ณผ์ •์—์„œ๋Š” ๋‹ค๋ฃจ์ง€ ์•Š์Œ (์‹ฌํ™” ๊ณผ์ •์—์„œ ๊ฐ€๋Šฅ)

๐Ÿ‘‰ ์šฐ๋ฆฌ๋Š” ์ „์—ญ SCSS + ๋ชจ๋“ˆ SCSS๋ฅผ ์กฐํ•ฉํ•ด์„œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.


2. ๊ธ€๋กœ๋ฒŒ ์Šคํƒ€์ผ (์ „์—ญ SCSS)

(1) styles/globals.scss ์ƒ์„ฑ

/* ๊ธ€๋กœ๋ฒŒ ์Šคํƒ€์ผ */
body {
  margin: 0;
  padding: 0;
  background: #fafafa;
  color: #222;
  font-family: "Noto Sans KR", sans-serif;
  line-height: 1.6;
}

a {
  color: #0070f3;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

(2) app/layout.tsx ์ˆ˜์ •

import { Noto_Sans_KR } from "next/font/google";
import Link from "next/link";
import '@/styles/globals.scss'; // ๊ธ€๋กœ๋ฒŒ SCSS ์ ์šฉ

// .. ์ดํ•˜ ์ƒ๋žต

3. ๋ ˆ์ด์•„์›ƒ์šฉ SCSS ๋ชจ๋“ˆ

(1) styles/layout.module.scss

.header {
  background: white;
  border-bottom: 1px solid #ddd;
  padding: 1rem;

  nav {
    display: flex;
    gap: 1rem;
  }
}

.container {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.footer {
  text-align: center;
  padding: 2rem 0;
  font-size: 0.9rem;
  color: #777;
  border-top: 1px solid #ddd;
}

(2) app/layout.tsx์— ์—ฐ๊ฒฐ

import { Noto_Sans_KR } from "next/font/google";
import Link from "next/link";
import '@/styles/globals.scss';
import styles from "@/styles/layout.module.scss";

const notoSansKR = Noto_Sans_KR({
  subsets: ["latin"],
  weight: ["400", "500", "700"],
});

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="ko">
      <body className={notoSansKR.className}>
        <header className={styles.header}>
          <nav>
            <Link href="/">ํ™ˆ</Link>
            <Link href="/about">์†Œ๊ฐœ</Link>
            <Link href="/posts">Posts</Link>
          </nav>
        </header>
        <main className={styles.container}>{children}</main>
        <footer className={styles.footer}>ยฉ 2025 My Next.js App</footer>
      </body>
    </html>
  );
}

4. ํŽ˜์ด์ง€ ์Šคํƒ€์ผ๋ง ๊ฐœ์„ 

(1) styles/home.module.scss ๊ฐœ์„ 

.title {
  font-size: 2.5rem;
  color: #0070f3;
  text-align: center;
  margin-top: 2rem;
}

.description {
  color: #555;
  text-align: center;
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

(2) app/page.tsx ์ ์šฉ

import styles from "@/styles/home.module.scss";

export default function Home() {
  return (
    <main>
      <h1 className={styles.title}>Hello Next.js ๐Ÿš€</h1>
      <p className={styles.description}>
        SCSS์™€ ๊ธ€๋กœ๋ฒŒ ๋ ˆ์ด์•„์›ƒ์„ ์ ์šฉํ•œ Next.js ๊ธฐ๋ณธ ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค.
      </p>
    </main>
  );
}

5. ์˜ค๋Š˜์˜ ์ •๋ฆฌ

  • ๊ธ€๋กœ๋ฒŒ SCSS(globals.scss) ์ ์šฉ โ†’ ํฐํŠธ/๊ธฐ๋ณธ ์Šคํƒ€์ผ ๊ด€๋ฆฌ
  • ๋ ˆ์ด์•„์›ƒ SCSS ๋ชจ๋“ˆ(layout.module.scss) ์ ์šฉ โ†’ Header/Footer/Container ์Šคํƒ€์ผ ๊ด€๋ฆฌ
  • ํŽ˜์ด์ง€ SCSS ๋ชจ๋“ˆ(home.module.scss)๋กœ ๊ฐœ๋ณ„ ์Šคํƒ€์ผ ์ ์šฉ
  • ๊ณตํ†ต ๋ ˆ์ด์•„์›ƒ(ํ—ค๋”/ํ‘ธํ„ฐ) ๊ตฌ์กฐ ์™„์„ฑ

๐Ÿ“š ์ €์žฅ์†Œ

GitHub - heroyooi/next-tutorial at ch1_4

๐Ÿ’ฌ ๋Œ“๊ธ€

    โ€ป ๋กœ๊ทธ์ธ ํ›„ ๋Œ“๊ธ€์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.