How to include Roboto font in webpack build for Material UI?

后端 未结 5 596
眼角桃花
眼角桃花 2021-01-30 03:45

For a progressive web app based on Material UI (React) and built with Webpack, how do I properly include Roboto font(s) so that the app does not depend

5条回答
  •  耶瑟儿~
    2021-01-30 04:26

    I tried installing typeface-roboto with npm but it didn't work. Also, using CDN from material ui didn't work. But, installing webfontloader with npm worked. Here is the solution, First,

    npm install webfontloader --save
    

    Then, import WebFont from webfontloader in your entry.js file for example App.js or index.js

    import WebFont from "webfontloader";
    WebFont.load({google: {families: ["Roboto:300,400,500"]}});
    

提交回复
热议问题