reactjs - 盖茨比不显示 Office UI Fabric React 图标
问题描述
我正在尝试让图标与 Gatsby 一起使用,但它们似乎没有在生产版本中显示。
我正在导入这样的图标
import {
initializeIcons
} from "office-ui-fabric-react"
并像这样调用函数
initializeIcons()
这都在我的index.js
页面文件中。这在运行时工作正常,gatsby develop
但是当我运行时gatsby build && gatsby serve
,图标会像这样显示。
但是,当我查看 Chrome 开发工具时,我可以看到正在下载的图标字体。
所以我假设这与 gatsby 的静态渲染有关。我从这个模板开始https://github.com/microsoft/gatsby-starter-uifabric
任何帮助表示赞赏。
解决方案
我遇到过同样的问题。在尝试了一堆变通方法后,我最终改用了office-ui-fabric-core。
安装库:
npm i office-ui-fabric-core
导入 ui-fabric-core css
import "office-ui-fabric-core/dist/css/fabric.css";
示例图标组件:
import React from "react";
const MyIcon = ({iconName}) => <i className={`ms-Icon ms-Icon--${iconName}`} aria-hidden="true"></i>
export default MyIcon;
示例用法:
<MyIcon iconName="People" />
推荐阅读
- php - 从另一个关联数组php的唯一值创建关联数组
- batch-file - 如何绕过将文件从多个位置移动到一个文件夹的限制
- c# - 从文件夹中替换/删除图像。C#
- c - _Bool 类型和严格别名
- node.js - 在nodejs中将缓冲流转换为pgm
- excel - 用于数据透视表参考的 Excel Vlookup 公式
- c++ - 调用可变参数函数模板时的 C++11 模棱两可的重载
- java - 我调用了一个 java 函数,我有 Stacktrace:] 根本原因在 JSP
- java - 关闭执行器服务(等待终止时)和等待取消提交的任务(使用提交的期货)之间的比较
- arrays - Using a list to select the same position in multiple arrays in Python