Gatsby入门-当我用google字体向public/index.html添加链接标记时,它在开发模式下工作。当我构建站点时,index.html会被重置。所以我猜还有另外一种适当的方式添加字体?
您还可以使用react-helmet,这在gatsby教程中进行了讨论。
在helmet组件中包含一个google字体链接元素。
像这样:
<Helmet>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"/>
</Helmet>
我最终走上了这条路,因为我已经手动做了一些样式,当我尝试使用排版时,它做了一堆更改,而这些更改需要我一段时间才能撤消。
在src/layouts/index.css
的顶部添加以下内容,例如通过Google导入'roboto'字体
@import url('https://fonts.googleapis.com/css?family=Roboto');
html {
font-family: 'Roboto', sans-serif;
}
然后,这将由gatsby构建过程处理,并包含在站点的最终生产版本中。