【发布时间】:2019-07-22 05:20:04
【问题描述】:
我正在尝试像下面的代码一样加载本地字体,但我不断收到Cannot find module '@/landing/fonts/Gotham-Bold.ttf' 错误并且不知道这条路径到底出了什么问题。
我的文件夹结构是这样的,我正在处理的代码是LandingPage.tsx
import { createGlobalStyle } from 'styled-components';
import font from './fonts/Gotham-Bold.ttf'
const Gotham = createGlobalStyle`
@font-face {
font-family: 'Gotham';
font-style: normal;
font-weight: bold;
src:
url(${font}) format('truetype'),
}
`
【问题讨论】:
-
你成功了吗?
-
这对我有用。像这样导入... src: url('../assets/fonts/gilroy/gilroy.woff2') format('woff2');
标签: javascript css reactjs fonts styled-components