Create-react-app: Load font (Semantic-UI React)

Created on 20 Dec 2016  路  11Comments  路  Source: facebook/create-react-app

Hey,

I'm tried to use CRA with Semantic UI React

http://react.semantic-ui.com/

Everything is good, but ONE feature doesnt work : the Icon.
Webpack can't load .woff and .ttf.

Here's my error with Firefox :

"downloadable font: invalid version tag (font-family: "Icons" style:normal weight:normal stretch:normal src index:2)
source http://localhost:3000/themes/default/assets/fonts/icons.woff

downloadable font: rejected by sanitizer (font-family : "Icons" style:normal weight:normal stretch:normal src index:2)
source http://localhost:3000/themes/default/assets/fonts/icons.woff"

I have the same error but with *.ttf files.

I suppose that with CRA, you can't add new loaders to Webpack right ?

Any ideas ?

Thanks a lot.

Most helpful comment

You also get this issue if you import font-awesome to a create react app.
Problem is that webpack needs this line of code to support WOFF, WOFF2, EOT, TTF and OTF font file types.
{
test: /.(woff|woff2|eot|ttf|otf)$/,
use: ['file-loader'],
},
Please make an option to extend the webpack config in some way.. Like angular have the angular.config file also should you make a react.config file to handle issues.

All 11 comments

Can you please provide a project reproducing the problem?

Isn't this related to this?
Your font may be 404'ing and since no hit to localhost:3000 will 404 (redirect to index.html) you get this weird error.
Both dev and prod webpack builds should support it.
Note that it also hashes the font filename. Your devil might be there.

I import css like this

import "semantic-ui-css/semantic.min.css"

inside my component and it's working.

I want to use icon with dropdown. It's working but when I click on the Icon there is like 0.5s before the dropdown open. It's really slow ...
When I use the same dropdown without icon, it's work with no delay.

My question is : Is it the good way to import semantic css ?

Can I ask you again to provide the project reproducing the issue?
It鈥檚 the quickest way to get help. 馃槈

I think the issue is that it needs a webpack config with a few extra loaders. Not sure if its possible to do this without ejecting?

You can see an example of the webpack config here:

https://github.com/Semantic-Org/Semantic-UI-React/blob/master/webpack.config.js

I just created a new project with create-react-app, then installed semantic-ui-react and semantic-ui-css, the Icon and fonts work fine.

when all else fails, just include it your public folder and reference the file from index.html. or use cdn.

Going to close since there was no project provided reproducing the issue.

You also get this issue if you import font-awesome to a create react app.
Problem is that webpack needs this line of code to support WOFF, WOFF2, EOT, TTF and OTF font file types.
{
test: /.(woff|woff2|eot|ttf|otf)$/,
use: ['file-loader'],
},
Please make an option to extend the webpack config in some way.. Like angular have the angular.config file also should you make a react.config file to handle issues.

@c0d3x Thank you, this resolved the issue for me, I added your snippet to the module.rules object in webpack.config.js.

@c0d3x any way to do this without ejecting?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alleroux picture alleroux  路  3Comments

JimmyLv picture JimmyLv  路  3Comments

fson picture fson  路  3Comments

alleroux picture alleroux  路  3Comments

Evan-GK picture Evan-GK  路  3Comments