Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  7] [ 2]  / answers: 1 / hits: 10996  / 3 Years ago, wed, february 10, 2021, 12:00:00

I'm attempting to use a @font-face declaration in my scss file.


The correct CSS rule is getting applied so the font-face declaration seems fine. The path is getting resolved as well so that's no issue. And, webpack throws no errors so it doesn't appear to be any kind of a loader issue. But in the end, the font is still not being rendered by the browser. (see image)


As of Webpack 5, the documentation states that you can declare in the rules "type: 'asset/resource'" to correctly load an asset such as a font or an image. It's working for the image I loaded, but not for the font.


CSS:


@font-face {
font-family: 'Yusei Magic', sans-serif;
font-style: normal;
font-weight: 400;
src: url('./assets/fonts/yusei-magic/YuseiMagic-Regular.ttf')
format('truetype');
}

Webpack config:


module: {
...
rules: [
...
{
test: /.ttf$/,
type: 'asset/resource',
},
],
},

More From » css

 Answers
5

When you're defining a @font-face declaration, on the font-family property, you must only write a string indicating how you will reference the font in your later styles.


In other words, I erroneously included "sans-serif" after "Yusei Magic" on the font-family property. This didn't throw an error, but it's incorrect CSS and thus was the source of my error. Thanks for anyone who chimed in!


[#1813] Wednesday, February 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylee

Total Points: 60
Total Questions: 119
Total Answers: 101

Location: Bonaire
Member since Wed, Mar 29, 2023
1 Year ago
;