【问题标题】:Using Fonts in SCSS with Webpack 4在 Webpack 4 中使用 SCSS 中的字体
【发布时间】:2019-01-10 04:13:16
【问题描述】:

我有一个带有 Webpack 4 的 Angular 6 SPA,用于基于以下 repo 进行捆绑;

AngularWebpackVisualStudio Example Repo

但是,我在将外部字体导入项目时遇到问题。通过查看webpack.dev.config.js,我有以下代码;

{
     test: /\.(png|jpg|gif|woff|woff2|ttf|svg|eot)$/,
     use: 'file-loader?name=assets/[name]-[hash:6].[ext]'
}

应该捆绑字体。我的 Angular 应用文件夹中有一个 .ttf 文件(/ClientApp/fonts/Font.ttf);

然后在我的app.component.scss 中我尝试添加以下内容;

@import '../fonts/Font.ttf';

@font-face {
    font-family: MyFont;
    src: url("../fonts/Font.ttf") format("opentype");
}

但是,当我运行该站点时,我的字体文件出现 404 错误? localhost/fonts/Font.tff

有人可以指导我这里做错了什么吗?

【问题讨论】:

    标签: angular webpack


    【解决方案1】:

    将字体添加到angular.jsonstyles:

    angular2-cli include custom fonts

    【讨论】:

      猜你喜欢
      • 2019-12-15
      • 2018-01-21
      • 2019-04-01
      • 1970-01-01
      • 2017-01-04
      • 2018-09-22
      • 2021-10-23
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多