next js 自定义字体在开发环境中工作正常,但是当我在本地构建它时它不起作用

问题描述 投票:0回答:1

我在我的应用程序中使用亚马逊字体 Ember 作为自定义字体,我在 lib 文件夹中设置了一个字体,ts 文件,并按照不同博客文章中的说明正确导出字体,并使其在我的开发服务器中工作,但是当我构建应用程序时,它的看看当我转到 localhost:3000 时,CSS 未加载,然后我转到 auth 页面,CSS 正确加载,返回到 / ,它开始正常工作,但字体未加载,它显示 systemUi 作为字体样式我什至在后备中也从未使用过,我使用的是 arial 和 san serif

这是我的代码

import localFont from "next/font/local";

const Ember = localFont({
    src: [
        {
            path: "../app/AmazonEmber_Th.ttf",
            weight: "100",
            style: "normal",
        },
        {
            path: "../app/AmazonEmber_Lt.ttf",
            weight: "200",
            style: "normal",
        },
        {
            path: "../app/AmazonEmber_Rg.ttf",
            weight: "400",
            style: "normal",
        },
        {
            path: "../app/Amazon-Ember-Medium.ttf",
            weight: "500",
            style: "normal",
        },
        {
            path: '../app/AmazonEmber_Bd.ttf',
            weight: "700",
            style: "normal",
        },
        {
            path: '../app/AmazonEmber_He.ttf',
            weight: "900",
            style: "normal",
        }
    ],
    variable: "--font-ember",
    display: "swap",
    fallback: ["sans-serif", "arial"],
});

export { Ember };

 my tailwind config file 


import type { Config } from "tailwindcss"

const config = {
  theme: {
    fontFamily: {
      Ember: ['var(--font-ember)', 'sans-serif']
    }
  },
  plugins: [require("tailwindcss-animate")],
} satisfies Config

export default config
in root layout <body className={${Ember.className} font-Ember}>

注意,我不使用默认根布局,我有组路线,每条路线都有自己的布局

css next.js fonts nextjs14
1个回答
0
投票

看起来你的代码没有问题。

  1. 验证字体路径是否正确并且在生产版本中可访问。
  2. 检查 Tailwind 是否正确配置。
  3. 查看 Next.js 构建日志中是否存在与字体或 CSS 相关的任何错误。
© www.soinside.com 2019 - 2024. All rights reserved.