我试图整合一些字体(FontAwesome,Roboto,...)我从 FontAwesome 开始
文件夹结构:项目文件夹
Projectfolder/assets/fonts/ // 这里所有的 ttf,eof,svg 文件
Projectfolder/public/ // index.html 和 app css 在这里
Projectfolder/web/ // webpack.config.js"
网络/webpack.config.js:
const appDirectory = path.resolve(__dirname, './../');
test: /\.js$/,
include: [
path.resolve(appDirectory, './assets'),
{...}
const ttfLoaderConfiguration = {
test: /\.ttf$/,
use: [
{
loader: 'file-loader',
options: {
name: './fonts/[hash].[ext]',
},
},
],
include: [
path.resolve(appDirectory, './src/assets'),
path.resolve(appDirectory, 'node_modules/react-native-vector-icons'),
path.resolve(appDirectory, './assets'),
],
};
应用程序.css:
#root {
display: flex;
flex-direction: column;
min-height: 100vh;
@font-face {
font-family: "FontAwesome";
src: url("../assets/fonts/FontAwesome.eot");
src: url("../assets/fonts/FontAwesome.eot") format("embedded-opentype"),
url("../assets/fonts/FontAwesome.woff2") format("woff2"),
url("../assets/fonts/FontAwesome.woff") format("woff"),
url("../assets/fonts/FontAwesome.ttf") format("truetype"),
url("../assets/fonts/FontAwesome.svg") format("svg");
font-weight: normal;
font-style: normal;
}
}
索引.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,
shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="manifest.json">
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="app.css">
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
</body>
<script src="assets/bundle.js"></script>
</html>
但是我得到的唯一结果是:有人遇到过这种情况并告诉我该怎么做吗?或者我做错了什么