2

I have created a javascript direflow application. I am trying to load a local font but haven't been able to.

Below are the details and code snippets I have applied.

Folder Structure enter image description here

font.css

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

direflow-components/testing-component/index.js

plugins: [
    {
      name: 'font-loader',
      options: {
        custom: {
          families: ['MyLocalFont'],
          urls: ['/fonts.css']
        },
      },
    },
  ],

App.css

.header-title {
  font-size: 34px;
  color: #5781C2;
  font-family: 'MyLocalFont';
}

The font files doesn't load. Please help.

Note: Built a react app using create-react-app there with @font-face changes the fonts load. Something with direflow is not working.

5
  • try create a build and then try again, sometimes the files don't get copied to your assets and as a result they don't get served. Commented Dec 23, 2020 at 10:44
  • There is no need to serve font files in .eot anymore, unless you're aiming for some backward compatibility of extreme level (caniuse.com/?search=eot). Also, in your css, you are referencing your woff2 file as if it was .woff and not .woff2 Commented Dec 23, 2020 at 17:11
  • @Capagris Thank you for pointing that out. I have corrected the WOFF file and font name but still, I don't see the fonts loading. Commented Dec 24, 2020 at 4:25
  • Try using file-loader instead. Commented Dec 24, 2020 at 4:31
  • @dhruwlalan no change. Commented Dec 24, 2020 at 4:57

1 Answer 1

3

I resolved the issue seems like the plugin font-loader is not required. I removed it from direflow-components/testing-component/index.js.

Another change I made is removed the single quotes from the font-family.

App.css

.header-title {
    font-family: MyLocalFont;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hey @Darshna Rekha, This doesn't seem to be working for me. The fonts are not even bundling in production build of direflow. Could you please help or provide code sample that you have?
Consider this is the path for the fonts for me testing-component/src/direflow-components/testing-component/fonts/Caveat-Bold.woff, I have added the font-face in testing-component/src/direflow-components/testing-component/App.css at the top of the page.

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.