Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the best way to include Google fonts (or any other) into create-react-based applications #2872

Closed
nnurmano opened this issue Jul 29, 2017 · 11 comments

Comments

@nnurmano
Copy link

As the subject suggest, I would like to receive a recommended way to including Google fonts into create-react-based applications.

@ianschmitz
Copy link
Contributor

The process doesn't need to be any different than usual when using CRA. You can simply add the font to your index.html, and use the index.css to specify your font styles.

@nnurmano
Copy link
Author

I came across this post, there are two options though.
https://stackoverflow.com/questions/41676054/how-to-add-fonts-to-create-react-app-based-projects, which lists two options.
In my case, I start off from scss file, where font is included and then css is created by using npm-sass-chokidar. As it is advised to generate css out of scss (not to store css file), it would be helpful to cover this option as well.

@ianschmitz
Copy link
Contributor

ianschmitz commented Jul 29, 2017

I believe that post was geared more towards using custom fonts. I'm guessing you are referring to using something such as Roboto? You shouldn't have any issues following the instructions on the Google page (i've used the same font in past).

@notrab
Copy link

notrab commented Jul 29, 2017

Place the import script inside index.html and away you go 😏

@robcaldecott
Copy link

You can import it!

npm install typeface-roboto --save

In index.js:

import "typeface-roboto";

That's it. Webpack will include the font files in your production builds.

All the Google fonts are on npm.

@robcaldecott
Copy link

Want Font Awesome? Also this simple:

npm install --save font-awesome

import "font-awesome/css/font-awesome.css";

HTH.

@gaearon gaearon closed this as completed Jul 31, 2017
@gaearon
Copy link
Contributor

gaearon commented Jul 31, 2017

I would just put them in public/index.html and src/index.css as suggested above.

@selrond
Copy link

selrond commented Feb 21, 2018

@robcaldecott Should be mentioned - only latin character set is currently supported

zhammer pushed a commit to zhammer/playlist-souffle that referenced this issue Jul 11, 2018
@ackvf
Copy link

ackvf commented Aug 21, 2018

For <link/> vs import - Is any one approach better than other - and why?

@OmarZeidan
Copy link

I would just put them in public/index.html and src/index.css as suggested above.

Hmm @gaearon , what about if you have 2 fonts? one for LTR and one for RTL? and you are using i18n or i18next to switch the language without the need for page reload?

Don't you think using something like webfontloader would help, like you listen to the language and load the needed font?

Would love hearing your thoughts.

@OmarZeidan
Copy link

For <link/> vs import - Is any one approach better than other - and why?

Well, I think that using <link> considered a rendering block and the page speed might yell at you.

On the other hand, using import would end up loading the system font first and the page will blink once the file get fetched and the font is ready to be used.

The blink will happen only once, the browser will cache it for you (make sure you don't have your devtool open and disable cache is enabled ;) it happened to me lol)

@lock lock bot locked and limited conversation to collaborators Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants