【问题标题】:ReactError: You may need an appropriate loader to handle this file typeReactError:您可能需要适当的加载程序来处理此文件类型
【发布时间】:2021-10-25 14:14:19
【问题描述】:

我有一个本地 RobotoFont.tff,我在 index.scss 文件中引用它,如下所示:

@font-face {
  font-family: 'Roboto';
  src: url('src/assets/Roboto/Roboto-Regular.ttf') format('truetype');
}
.rb {font-family: 'Roboto';}

但我在编译时收到以下错误:

Failed to compile.

./src/assets/Roboto/Roboto-Regular.ttf 1:0
Module parse failed: Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

该项目在 React-Typescript 中,我是否需要安装链接中指定的任何特定加载器?如果是,它适用于 .ttf 文件吗?

【问题讨论】:

标签: reactjs typescript webpack fonts


【解决方案1】:

试试file-loaderurl-loader

例如 webpack.config.js

     {
        test: /\.(png|gif|woff|woff2|eot|ttf|svg)$/,
        loader: 'url-loader',
      },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 2018-02-01
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    相关资源
    最近更新 更多