next localFont ์‚ฌ์šฉ ์ด์œ ์™€ src ์„ค์ •

ํ”„๋กœ์ ํŠธ์—์„œ app ํด๋” ๋‚ด์˜ fonts ํด๋”๋ฅผ public ํด๋”๋กœ ์ด๋™ํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ–ˆ๋‹ค.

ํฐํŠธ ์„ค์ •์€ ๋‹ค๋ฅธ ํŒ€์›๋ถ„์ด ๋งก์œผ์…จ๊ณ , next/font๋ฅผ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์•˜๋‹ค.

import localFont from 'next/font/local';
import '@/globals.css';

const pretendard = localFont({
  src: '../fonts/PretendardVariable.woff2',
  display: 'swap',
  weight: '45 920',
  variable: '--font-pretendard',
});

...

const RootLayout = async ({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) => {
  return (
    <html lang="ko">
      <body className={`${pretendard.variable} antialiased`}>
        ...
        {children}
      </body>
    </html>
  );
};

export default RootLayout;

 

์ด ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๋‘ ๊ฐ€์ง€ ์˜๋ฌธ์ ์ด ์ƒ๊ฒผ๋‹ค.

  1. ์™œ global.css ๋Œ€์‹  next/font๋ฅผ ์‚ฌ์šฉํ• ๊นŒ?
  2. ๊ฐ‘์ž๊ธฐ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์˜ ์›์ธ์€?

 

์ด ๋‘๊ฐ€์ง€๋ฅผ ์ •๋ฆฌ๋ณด๊ณ ์ž ํ•œ๋‹ค.

 

 


 

์™œ global.css ๋Œ€์‹  next/font๋ฅผ ์‚ฌ์šฉํ• ๊นŒ?

Next.js 13๋ฒ„์ „๋ถ€ํ„ฐ ์ถ”๊ฐ€๋œ next/font๋Š” font๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์ตœ์ ํ™” ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€๋˜์—ˆ๋‹ค.

 

 

 

์„ฑ๋Šฅ ์ตœ์ ํ™”

 

1. ์ž๋™ ์„œ๋ธŒ์…‹ํŒ…

  • ์‚ฌ์šฉ์ž๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ๋ฌธ์ž๋งŒ ํฌํ•จ๋œ ์„œ๋ธŒ์…‹์„ ์ƒ์„ฑํ•ด ํฐํŠธ ํŒŒ์ผ ํฌ๊ธฐ๋ฅผ ์ค„์ธ๋‹ค.
  • ๋งŒ์•ฝ ์‚ฌ์ดํŠธ์—์„œ ์˜์–ด๋งŒ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ์˜์–ด ๋ฌธ์ž๋งŒ ํฌํ•จ๋œ ํฐํŠธ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ๋ถˆํ•„์š”ํ•œ ๋‹ค๋ฅธ ์–ธ์–ด ๋ฌธ์ž๋ฅผ ๋บ€๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ํŽ˜์ด์ง€ ๋กœ๋”ฉ์ด ํ›จ์”ฌ ๋นจ๋ผ์ง„๋‹ค

 

2. ๋ Œ๋”๋ง ์ตœ์ ํ™”

  • ํฐํŠธ๊ฐ€ ๋กœ๋“œ๋  ๋•Œ ํ™”๋ฉด์ด ๊นœ๋นก์ด๊ฑฐ๋‚˜ ํ…์ŠคํŠธ๊ฐ€ ์•ˆ ๋ณด์ด๋Š” ํ˜„์ƒ์„ ๋ฐฉ์ง€ํ•œ๋‹ค.
  • display: swap์„ค์ •์œผ๋กœ ํฐํŠธ๊ฐ€ ๋กœ๋”ฉ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋ณธ ํฐํŠธ๋กœ ๋จผ์ € ํ…์ŠคํŠธ๋ฅผ ๋ณด์—ฌ์ค˜์„œ, ์‚ฌ์šฉ์ž๊ฐ€ ๋นˆ ํ™”๋ฉด์„ ๋ณด์ง€ ์•Š๋„๋ก ํ•œ๋‹ค.

 

 

 

๊ฐ„ํŽธํ•œ ํฐํŠธ ๊ด€๋ฆฌ

 

1. ๋ถˆํ•„์š”ํ•œ ์™ธ๋ถ€ ์š”์ฒญ ๋ฐฉ์ง€

  • Google Fonts ๊ฐ™์€ ์™ธ๋ถ€ ์„œ๋น„์Šค๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋Œ€์‹ , ํฐํŠธ๋ฅผ ํ”„๋กœ์ ํŠธ ์•ˆ์— ์ง์ ‘ ํฌํ•จ์‹œ์ผœ์„œ ์™ธ๋ถ€ ์š”์ฒญ์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.

 

2. ๋นŒ๋“œ ํƒ€์ž„ ์ตœ์ ํ™”

  • ํฐํŠธ๊ฐ€ ์›น์‚ฌ์ดํŠธ๋ฅผ ๋นŒ๋“œํ•  ๋•Œ ์ฒ˜๋ฆฌ๋˜์–ด, ์‚ฌ์ดํŠธ๊ฐ€ ์‹ค์ œ๋กœ ์‹คํ–‰๋  ๋•Œ ๋” ๋น ๋ฅด๊ฒŒ ์ž‘๋™ํ•œ๋‹ค.

 

 

 

์œ ์—ฐํ•œ ์ปค์Šคํ…€ ์˜ต์…˜

 

1. ๊ฐ€๋ณ€ ํฐํŠธ ์ง€์›

  • ํ•˜๋‚˜์˜ ํฐํŠธ ํŒŒ์ผ๋กœ ์—ฌ๋Ÿฌ ๊ตต๊ธฐ์™€ ์Šคํƒ€์ผ์„ ์ง€์›ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๊ตต์€ ๊ธ€์”จ์™€ ์–‡์€ ๊ธ€์”จ๋ฅผ ๋”ฐ๋กœ ๋กœ๋“œํ•˜์ง€ ์•Š๊ณ , ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ๋‹ค์–‘ํ•œ ์Šคํƒ€์ผ์„ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์–ด์„œ ๋กœ๋”ฉ ์†๋„๊ฐ€ ๋นจ๋ผ์ง„๋‹ค.

 

2. ์ปค์Šคํ…€ ํฐํŠธ

  • ๋กœ์ปฌ์— ์ €์žฅ๋œ ํฐํŠธ๋‚˜ ๋‹ค๋ฅธ ์›น ํฐํŠธ ์ œ๊ณต์ž์˜ ํฐํŠธ๋„ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

next/font์„ค์ • ์ค‘ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ

ํฐํŠธ ํŒŒ์ผ ์œ„์น˜๋ฅผ publicํด๋”๋กœ ์˜ฎ๊ธฐ๊ณ  src ๊ฒฝ๋กœ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ–ˆ๋‹ค.

const pretendard = localFont({
  src: '/public/fonts/PretendardVariable.woff2',
  display: 'swap',
  weight: '45 920',
  variable: '--font-pretendard',
});

 

ํ•˜์ง€๋งŒ ์—๋Ÿฌ ๋ฐœ์ƒ๐Ÿ˜ฅ ๊ฐ‘์ž๊ธฐ ./๋Š” ์–ด๋””์„œ ๋‚˜ํƒ€๋‚œ ๊ฑฐ์ง€..?

 

 

๋‹ค์–‘ํ•œ ์‹œ๋„

  1. /public/fonts → ์‹คํŒจ
  2. ../public/fonts → ์‹คํŒจ
  3. @/public/fonts → ์‹คํŒจ
  4. /fonts → ์‹คํŒจ
  5. ../fonts → ์‹คํŒจ
  6. ../../public/fonts → ์„ฑ๊ณต!๐ŸŽ‰

 

 

์›์ธ : ์ƒ๋Œ€ ๊ฒฝ๋กœ์˜ ์ค‘์š”์„ฑ

localFont์—์„œ๋Š” src๋Š” ์ƒ๋Œ€ ๊ฒฝ๋กœ๋กœ ์„ค์ •ํ•ด์•ผ ํ•œ๋‹ค. publicํด๋” ์•ˆ์— ์žˆ๋Š” ํฐํŠธ ํŒŒ์ผ๋„ ์ƒ๋Œ€ ๊ฒฝ๋กœ๋กœ ์ ‘๊ทผํ•ด์•ผ ํ–ˆ๋‹ค.

const pretendard = localFont({
  src: '../../public/fonts/PretendardVariable.woff2',
  display: 'swap',
  weight: '45 920',
  variable: '--font-pretendard',
});

 


 

๊ฒฐ๋ก 

  1. next/font๋Š” ์„ฑ๋Šฅ ์ตœ์ ํ™”, ์„œ๋ธŒ์…‹ํŒ…, ๋ Œ๋”๋ง ๊ฐœ์„  ๋“ฑ์œผ๋กœ global.css๋ณด๋‹ค ํšจ์œจ์ ์ด๋‹ค.
  2. localFont๋Š” ์ƒ๋Œ€ ๊ฒฝ๋กœ๋กœ ์ ‘๊ทผํ•ด์•ผ ํ•œ๋‹ค.

ํ—ˆ๋ฌดํ•œ ๊ฒฐ๋ง์ด์ง€๋งŒ, ํ•ด๊ฒฐํ–ˆ์œผ๋‹ˆ ๋งŒ์กฑํ•œ๋‹ค…๐Ÿ™ƒ