reactjs 在NextJS应用程序中正确使用ttf字体

7uzetpgm  于 2024-01-07  发布在  React
关注(0)|答案(1)|浏览(154)

我在我的NextJS应用程序中使用我的本地字体,并通过我的globals.css,它工作正常,如:

@font-face {
  font-family: "PrometoRegular";
  src: local("PrometoRegular");
  src: url('../assets/fonts/Prometo-Regular.ttf') format('truetype');
}
h1 {
  font-family: "PrometoRegular";
  color: black;
}

字符串
但是当我想在一个组件中这样做时:import PrometoRegular from '../../../assets/fonts/Prometo-Regular.ttf';
返回You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file
我如何配置我的next.config.js文件,使它将工作?

jhkqcmku

jhkqcmku1#

根据文件,它提到,

来源

指定字体的来源。如果你在Node上使用react-pdf,它可以是 * 一个有效的URL*,也可以是 * 一个绝对路径 *。
你可以把它放在你的公共目录,并把它作为一个网址。

相关问题