Skip to content

Instantly share code, notes, and snippets.

@timbophillips
Created January 1, 2019 00:44
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save timbophillips/455ac41659fddcd774c5550650665b66 to your computer and use it in GitHub Desktop.
Save timbophillips/455ac41659fddcd774c5550650665b66 to your computer and use it in GitHub Desktop.
host roboto font and material icons locally in angular app
//// npm install --save roboto-fontface material-icons
//// put the below stuff into src/styles.scss
// for npm roboto-fontface package (to load local files)
$roboto-font-path: "~roboto-fontface/fonts" !default;
@import "~roboto-fontface/css/roboto/sass/roboto-fontface";
// for npm material-icons package (to load local files)
$material-icons-font-path: '~material-icons/iconfont/';
@import '~material-icons/iconfont/material-icons.scss';
@dayanrr91
Copy link

like a charm... thanks :)

@sterlp
Copy link

sterlp commented May 8, 2020

very nice

@pette9
Copy link

pette9 commented Jul 3, 2020

Works great. Thanks

@ajaysattikar
Copy link

Perfect, thanks a lot!

@anirudhr95
Copy link

Works great :)

@kpeterbauer
Copy link

You are my hero!

@swennijboer
Copy link

Awesome thanks!

@aboudard
Copy link

aboudard commented Feb 7, 2022

Brilliant ! Thanks for that !

@cssriraman
Copy link

Awesome Thank you :)

@markushaslinger
Copy link

With a lawyer in my country going nuts right now on referencing Google Fonts remotely (GDPR...) this is exactly what I needed, many thanks.

@otembajelle
Copy link

It worked right out of the box. The only problem was the migration to Sass. It complains ...
imports '~roboto-fontface/css/roboto/sass/roboto-fontface' with a tilde. Usage of '~' in imports is deprecated. but that did not spoil it.

@DonDozone
Copy link

DonDozone commented Nov 30, 2022

Since Angular & Material v15 I get an error during build process:

./src/styles.scss - Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
   ╷
23 │ @import '~material-icons/iconfont/material-icons.scss';
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  src/styles.scss 23:9  root stylesheet

./src/styles.scss?ngGlobalStyle - Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
   ╷
23 │ @import "~roboto-fontface/css/roboto/sass/roboto-fontface";
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  src/styles.scss 23:9  root stylesheet

Anyone knows how to solve it?

I tried the following suggestion: Add

"stylePreprocessorOptions": {
              "includePaths": [
                "./node_modules"
              ]
            },

in angular.json and remove the ~ from the imports. But this still loads the files from google and also leads to a 404 for the local files

@DonDozone
Copy link

Apparently this isssue is fixed with Angular 15.0.2 again. Did not change the build, but now it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment