css 将自定义字体添加到React-Native-Web

j8ag8udp  于 2022-11-26  发布在  React
关注(0)|答案(1)|浏览(144)

我试图整合一些字体(FontAwesome,Roboto,...)我开始与FontAwesome
文件夹结构:项目文件夹
项目文件夹/assets/fonts/ //所有ttf、eof、svg文件在此处
项目文件夹/public//index. html和应用程序css在此处
项目文件夹/web/ //webpack. config. js”
Web/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>

但我得到的唯一结果是:有没有人经历过这种情况,并告诉我如何做?或者我做错了什么

ubof19bj

ubof19bj1#

经过大量的研究终于,我在这个环节找到了解决的办法:
矢量图标未显示在react native for web中

相关问题