I am importing a font in Angular 9 app style.scss using the following syntax:
@import url('https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap');
This works when I run ng serve. However, the import does not seem to work when the Angular bundle is deployed in the production mode. The production bundle makes no attempt to load this font - there is no network request. Further there are no errors in the Chrome console.
I have locally installed fonts that do work - so I suspect this has something to do with third-party hosted fonts:
@font-face {
font-family: Korolev;
font-weight: 600;
font-style: normal;
src: url('assets/fonts/korolev-medium-webfont.ttf');
}
Tracing down the error, it is related to something called injectStylesIntoStyleTag.js, from a Webpack style-loader. This seems to do the trick when ng serve is run in the development mode, as we can see a request initiated from the script that creates <style> in the head that loads the font. However, when run in the production mode either the mechanism to load fonts is different or it does not seem to kick in.
Should SCSS imports from third party work normally in Angular production mode?
If
importfor third party fonts is not recommended, what is the preferred mechanism to use third party fonts in stylesheets?
