简体   繁体   English

Font-Awesome 5 PRO in rails 5 app

[英]Font-Awesome 5 PRO in rails 5 app

In order to access to the benefits of the pro package, adding font-awesome 5 from the gem is not possible. 为了获得专业软件包的好处,无法从gem中添加font-awesome 5。

Tried diferent ways to add the files provided to the project. 尝试了不同的方法来添加提供给项目的文件。 Following Official guide 遵循官方指南

Package content: 包装内容:

在此输入图像描述

I saw in other stackoverflow posts, that the correct way to add it to the app is in 我在其他stackoverflow帖子中看到,将其添加到应用程序的正确方法是

vendor/assets/

But after that, puting /on-server/'s css, js, and font or the /web-fonts-with-css/ files still didn't work. 但在那之后,put / on-server /的css,js和font或/ web-fonts-with-css / files仍然无法正常工作。

Tried adding custom stylesheet link, require and import in scss. 尝试添加自定义样式表链接,需要并在scss中导入。 No way to achieve it. 无法实现它。

Hope I've been clear. 希望我已经清楚了。

Using the 'Web Fonts with CSS' approach has a wrinkle because the font url is hardcoded into the CSS file, but it can be done. 使用'Web字体与CSS'方法有一个皱纹,因为字体网址被硬编码到CSS文件中,但它可以完成。

CSS: CSS:

Copy the fontawesome-all.css to the 'vendor/assets/stylesheets' folder. 将fontawesome-all.css复制到'vendor / assets / stylesheets'文件夹。

Update your app/assets/stylesheets/application.css file with 使用更新您的app / assets / stylesheets / application.css文件

 *= require fontawesome-all

Fonts: 字体:

Then copy the webfonts folder to the public dir so all the fonts are in the public/webfonts folder. 然后将webfonts文件夹复制到公共目录,以便所有字体都在public / webfonts文件夹中。

Restart your server and you should now be able to see your FA5 fonts. 重新启动您的服务器,您现在应该能够看到您的FA5字体。

SVG with JS 带JS的SVG

If you want to make it even easier (only 1 file to track) then you can do the 'SVG with JS' approach. 如果你想让它变得更容易(只有一个文件可以跟踪)那么你可以使用'SVG with JS'方法。

JS: JS:

Copy the fontawesome-all.js to the 'vendor/assets/javascripts' folder. 将fontawesome-all.js复制到'vendor / assets / javascripts'文件夹。

Update your app/assets/stylesheets/application.js file with 使用更新您的app / assets / stylesheets / application.js文件

 //= require fontawesome-all

Restart your server and you are good to go. 重新启动服务器,你很高兴。

There is also a way to use raw svg without any js and thus avoiding rendering issues and nasty hacks that lead to annoying flickering side effects 还有一种方法可以使用没有任何js的原始svg,从而避免渲染问题和讨厌的黑客导致恼人的闪烁副作用

It comes in the form of a view helper called faw_icon https://github.com/alexwebgr/faw_icon and it provides three ways to load svg into your application 它以视图助手的形式出现,名为faw_icon https://github.com/alexwebgr/faw_icon ,它提供了三种将svg加载到应用程序中的方法

  1. using the icons.json from the metadata 使用元数据中的icons.json
  2. using the raw single svg files 使用原始的单个svg文件
  3. using the svg sprites 使用svg精灵

by design it doesn't bundle any icons catering for a small download size and giving the developers the ability to update the icon sets as new ones become available, use custom ones or the PRO collection 根据设计,它不捆绑任何符合较小下载大小的图标,并使开发人员能够在新图标集可用时更新图标集,使用自定义图标集或PRO集合

If you are using rails which supports Node Modules. 如果您使用支持节点模块的rails。

  1. Add Configuration 添加配置
npm config set "@fortawesome:registry" https://npm.fontawesome.com/ && \
  npm config set "//npm.fontawesome.com/:_authToken" YOUR_AUTH_TOKEN

OR 要么

Save configuration in file .npmrc in app root folder as below 将配置保存在app根文件夹中的.npmrc文件中,如下所示

@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=YOUR_AUTH_TOKEN
  1. Run NPM or YARN to install the package 运行NPM或YARN以安装软件包
npm install --save @fortawesome/fontawesome-pro

OR 要么

yarn add @fortawesome/fontawesome-pro
  1. Add the packages in app/assets/application.js file app / assets / application.js文件中添加包
//= require @fortawesome/fontawesome-pro/js/all.min.js

  1. Include Node Modules folder in assets path by adding below line in config/application.rb 通过在config / application.rb中添加以下行,在资源路径中包含Node Modules文件夹
config.assets.paths << Rails.root.join('node_modules')

Start the server again and you are good to go with font-awesome PRO . 再次启动服务器,你可以使用font-awesome PRO

For more details you can visit the below link: 有关详细信息,请访问以下链接:

https://fontawesome.com/how-to-use/on-the-web/setup/using-package-managers https://fontawesome.com/how-to-use/on-the-web/setup/using-package-managers

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM