๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป DEV/NextJS

[NEXT.js 14] 4. Font ๋ฐ”๊พธ๊ธฐ

by Rising Oneโ˜… 2024. 6. 17.
728x90
๋ฐ˜์‘ํ˜•
SMALL

 

NEXT.js ์—์„œ๋Š” 'next/font/google'์™€ ๊ฐ™์ด google font ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‚ด์žฅํ•˜๊ณ  ์žˆ์–ด ์ ‘๊ทผ์„ฑ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

๋ฟ๋งŒ ์•„๋‹ˆ๋ผ 'next/font'๋Š” ๋ชจ๋“  ๊ธ€๊ผด ํŒŒ์ผ์— ์ž๋™์ ์œผ๋กœ ์ž์ฒด ํ˜ธ์ŠคํŒ…์ด ๋‚ด์žฅ๋ผ ์žˆ๊ณ ,

์ด๋ฅผ ์ ์šฉํ•˜๊ณ ์„œ ๋ ˆ์ด์•„์›ƒ(๋ทฐ)์˜ ์‰ฌํ”„ํŠธ(๊นœ๋นก์ž„, ๊ธ€๊ผด์˜ ์ˆœ๊ฐ„์  ๋ณ€ํ™” ๋“ฑ) ์—†์ด ํฐํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Font ๋ฐ”๊พธ๊ธฐ

 

  1. import {...} from 'next/font/google'; 

 

  2. layout.tsx ๋˜๋Š” Font.ts ์ปดํฌ๋„ŒํŠธ์— ์‚ฌ์šฉํ•  Font ์ž‘์„ฑ

 

  3. tailwind.config.ts ์ž‘์„ฑ 

 

  4. tailwind css ํ‘œ๊ธฐ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ


์ƒ์„ธ

  1. import {...} from 'next/font/google'; 

# app/font.ts

import { Font๋ช…์นญ } from 'next/font/google';

 

  2. layout.tsx ๋˜๋Š” Font.ts ์ปดํฌ๋„ŒํŠธ์— ์‚ฌ์šฉํ•  Font ์ž‘์„ฑ

# app/font.ts

import { ABeeZee } from 'next/font/google';

export const abeezee = ABeeZee(
  {
    subsets: ['latin'],
    variable: '--font-abeezee',
    weight: '400',
    display: 'swap',
  });

 

  3. tailwind.config.ts ์ž‘์„ฑ 

# /tailwind.config.ts

import type {Config} from "tailwindcss";

const config: Config = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./components/**/*.{js,ts,jsx,tsx,mdx}",
    "./app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {
      fontFamily: {
        abeezee: ['var(--font-abeezee)'],
      },
    },
  },
  plugins: [],
};

export default config;

 

  4. tailwind css ํ‘œ๊ธฐ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ

(1) global.css

@tailwind base;
@tailwind components;
@tailwind utilities;

body {
    @apply font-abeezee text-white
}

 

(2) page.tsx

# ์ ์šฉํ•  page

export default function Home() {
  return (
    <>
      <div className="main-bg font-abeezee">
        ...
      </div>
    </>
  );
}

 

NextJS ๊ณต์‹๋ฌธ์„œ: Optimization > Font

728x90
๋ฐ˜์‘ํ˜•
LIST

๋Œ“๊ธ€