question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Font-face not loading properly

See original GitHub issue

Hey 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 😕

screen shot 2016-07-19 at 1 09 00 pm

Any ideas?

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
thani-shcommented, Jul 19, 2016

Hi @renanvalentin Add the -s switch with start-storybook command as explained here.

start-storybook -p 6977 -s ./public
9reactions
Aarbelcommented, May 3, 2018

I solved it using a static on storybook-start :

start-storybook -p 9001 -c .storybook watch-css -s ./src

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found