简体   繁体   English

在React应用程序中嵌入字体的选项?

[英]Options for embedding fonts in a React app?

Is there a way that I can convert a font file to a buffer or svgs or something and embed it within a js bundle? 有没有一种方法可以将字体文件转换为缓冲区或svgs或其他内容并将其嵌入js包中?

The way the app will be used means I can't link to a hosted font file and I won't have access to the local file system. 应用程序的使用方式意味着我无法链接到托管字体文件,也无法访问本地文件系统。

Thanks for any info. 感谢您提供任何信息。

You can include ttf (font files) into your project and then modify your config.js to bundle it together: 您可以在项目中包含ttf(字体文件),然后修改config.js以将其捆绑在一起:

let rules = []  
  rules.push({
      test: /\.ttf$/,
      loader: 'file-loader',
      options: {name: 'fonts/[name].[ext]'}
    })

    module.exports = () => {
      module: { rules },
      ...
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在现有的 Rails 应用程序中嵌入 React 应用程序 - Embedding a React App in an existing Rails App 在 React App 中嵌入 TikTok 视频; 视频不显示 - Embedding TikTok Video in React App; Video not showing 在反应应用中将Google日历作为iframe嵌入? - Embedding Google calendar as iframe in a react app? 在现有应用程序中将React应用程序与React-Router 4嵌入 - Embedding React app with React-Router 4 in Existing App Fonts 未在使用 Expo 构建的 React Native App 中加载 - Fonts not loading in React Native App built with Expo 使用 Javascript 将 React 应用程序嵌入为小部件失败,并在 Firefox 和 Chrome 上显示不同的消息 - Embedding React app as a widget with Javascript is failing with different messages on Firefox and Chrome 使用 Google Tag Manager 在另一个网站中嵌入 React 应用程序<script> - Embedding React app in another website with Google Tag Manager using <script> cufon帮助嵌入2种字体而忽略第一条规则 - cufon help embedding 2 fonts ignoring first rule 用于在 web 应用程序的 HTML 上实现 PowerPoint 查看器的选项(使用提供的 i-frame 标签嵌入除外) - options for implementing a PowerPoint viewer on HTML for a web app (other than embedding with provided i-frame tag) 在选项中嵌入多个值<select> - embedding multiple values in options of <select>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM