【问题标题】:Add custom Font to .NET Core 2.0 Angular将自定义字体添加到 .NET Core 2.0 Angular
【发布时间】:2018-01-08 21:39:52
【问题描述】:

我有一个使用 Angular 2 模板的 .NET Core 2.0 应用程序。

问题是我无法在 app.component.css 中添加自定义字体 (woff2)

@font-face {
    font-family: 'FrutigerBold';
    src: url("./assets/fonts/frutiger65_bold.woff2") format('woff2');
}

并得到以下错误:

NodeInvocationException:预渲染因错误而失败:错误:模块解析失败:C:\Users\gbuenrostro\documents\visual studio 2017\Projects\SecurityAngular\SecurityAngular\ClientApp\app\assets\fonts\frutiger65_bold.woff2 意外字符' �' (1:4)

您可能需要适当的加载程序来处理此文件类型。

(此二进制文件的源代码省略)

有什么想法吗?

这是项目:

【问题讨论】:

  • 该错误出现在哪里?在浏览器控制台中还是在构建期间或运行时?
  • 它发生在角度构建期间。

标签: css angular asp.net-core-2.0


【解决方案1】:

不要在 app.component.css 中添加 css。 创建一个 file.css 以包含字体(然后不放在资产文件夹中)并更改 webpack.config.vendor 在 nonTreeShakableModules 中添加文件

const nonTreeShakableModules = [
    ...
    'file.css',
    ...
];

【讨论】:

  • 该解决方案的问题是,每当我想更改该 file.css 中的某些内容时,更改不会反映在项目中,必须重新编译供应商 css。
  • 在 index.html 中包含字体怎么样?
猜你喜欢
  • 2018-04-22
  • 1970-01-01
  • 2022-11-30
  • 2016-08-11
  • 2021-09-04
  • 2017-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多