Font-face not loading properly
See original GitHub issueHey guys nice work!!!
I’ve could setup and running storybook, but I wasn’t able to load static files:
this is my config:
package.json:
"storybook": "start-storybook -p 9001"
webpack.config:
const path = require('path');
const localIdentName = '[name]__[local]___[hash:base64:5]';
const cssLoader = [
'css?minimize&modules',
'sourceMap',
'importLoaders=1',
'localIdentName=' + localIdentName
].join('&');
const fontsFileName = `fonts/[name].[ext]`;
const imagesFileName = `img/[name].[ext]`;
module.exports = {
resolve: {
root: path.resolve(__dirname, '../src'),
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.scss$/,
include: path.resolve(__dirname, '../src'),
loaders: [
'style',
cssLoader,
'postcss-loader',
'sass?sourceMap'
]
},
{
test: /\.woff(\?.*)?$/,
loader: `url?prefix=fonts/&name=${fontsFileName}&limit=10000&mimetype=application/font-woff`,
},
{
test: /\.woff2(\?.*)?$/,
loader: `url?prefix=fonts/&name=${fontsFileName}&limit=10000&mimetype=application/font-woff2`
},
{
test: /\.ttf(\?.*)?$/,
loader: `url?prefix=fonts/&name=${fontsFileName}&limit=10000&mimetype=application/octet-stream`
},
{test: /\.eot(\?.*)?$/, loader: `file?prefix=fonts/&name=${fontsFileName}`},
{test: /\.svg(\?.*)?$/, loader: `url?prefix=fonts/&name=${fontsFileName}&limit=10000&mimetype=image/svg+xml`},
{test: /\.(png|jpg)$/, loader: `url?limit=5192&name=${imagesFileName}`}
]
},
sassLoader: {
includePaths: path.resolve(__dirname, '../src/styles')
}
};
this is the output created by webpack:
@font-face{
font-family:lato;src:url(/static/fonts/Lato-Regular.ttf);
font-weight:400;
font-style:normal
}
@font-face{
font-family:lato;src:url(/static/fonts/Lato-Semibold.ttf);
font-weight:600;
font-style:normal
}
@font-face{
font-family:lato;
src:url(/static/fonts/Lato-Light.ttf);
font-weight:300;
font-style:normal
}
If I hit localhost:9001/static/fonts/Lato-Regular.ttf it will download the font properly, but when I load the page it is not loaded 😕
Any ideas?
Thanks in advance!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:10 (2 by maintainers)
Top Results From Across the Web
css - @font-face not working - Stack Overflow
Check your resources tab in the inspector/firebug to make sure your fonts are being loaded correctly. · Just a suggestion: check out Google...
Read more >How to use @font-face in CSS
The @font-face rule allows custom fonts to be loaded on a webpage. Once added to a stylesheet, the rule instructs the browser to...
Read more >css - Custom font not loading - Webmasters Stack Exchange
Yes, I am loading the external stylescript in the head, just like the main CSS file. I checked all the syntax and spelling;...
Read more >How to load web fonts to avoid performance issues and speed ...
Use the correct font format ; Preload fonts; Use the correct font-face declaration; Avoid invisible text during font loading. Let's break down ...
Read more >Optimize WebFont loading and rendering - web.dev
The first period is the font block period. During this period, if the font face is not loaded, any element attempting to use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @renanvalentin Add the
-s
switch withstart-storybook
command as explained here.I solved it using a static on storybook-start :
start-storybook -p 9001 -c .storybook watch-css -s ./src