0

Having problem with using web-font in CRA, in development mode it loads like this

Font is loaded

But when deployed, in production mode it doesn't seemed to be loaded at all. Any ideas guys? Here is my css

    @font-face {
      font-family: 'Noto Sans';
      src: local('Noto Sans KR'), url(./fonts/NotoSansKR-Black.otf) format('opentype');
      font-weight: 900;
    }

    @font-face {
      font-family: 'Noto Sans';
      src: local('Noto Sans KR'), url(./fonts/NotoSansKR-Bold.otf) format('opentype');
      font-weight: 700;
    }

2 Answers 2

0

During production, your fonts get bundled as base64 Uri, if you have code splitting enabled then you can see them in your chunks list with a different hashed name.

Sign up to request clarification or add additional context in comments.

1 Comment

But still, why the fonts are not being applied in production?
0

This is the suggested option. It ensures your fonts go through the build pipeline, get hashes during compilation so that browser caching works correctly, and that you get compilation errors if the files are missing.

As described in “Adding Images, Fonts, and Files”, you need to have a CSS file imported from JS. For example, by default src/index.js imports src/index.css:

import './index.css'; A CSS file like this goes through the build pipeline, and can reference fonts and images. For example, if you put a font in src/fonts/MyFont.woff, your index.css might include this:

@font-face {
  font-family: 'MyFont';
  src: local('MyFont'), url(./fonts/MyFont.woff) format('woff');
}

Notice how we’re using a relative path starting with ./. This is a special notation that helps the build pipeline (powered by Webpack) discover this file. Answered here: How to add fonts to create-react-app based projects?

3 Comments

Did you delete my comment? Anyways, don't copy another person's answer
I mentioned, that this is your answer.
No.. This is NOT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.