Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  144] [ 3]  / answers: 1 / hits: 17241  / 9 Years ago, thu, october 22, 2015, 12:00:00

I have this code in a React element:



require('../../Style/fonts/SomethingStrange.ttf')


In my Webpack.config:



{ test: /.(ttf|otf|eot|svg|woff(2)?)(?[a-z0-9]+)?$/, 
loader: 'file-loader?name=fonts/[name].[ext]' }


Problem: no font on my webpages...



Doesn't Webpack let me automatically require fonts? Do I have to program anything else to load fonts?


More From » reactjs

 Answers
27

You have to require your fonts inside css files, not inside js/jsx files. For example:



@font-face {
font-family: 'SomethingStrange';
src: url('../../Style/fonts/SomethingStrange.ttf');
}

[#64634] Wednesday, October 21, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;