Introduction
When using Fontsource in a Sass/SCSS project, you will need to configure your Sass compiler to resolve the pkg:
import directive to resolve the font stylesheets from the NPM package.
Configuration
It is required to use Dart Sass v1.71.0
or later to resolve the pkg:
import directive.
Command Line
If you are using the command line to compile your Sass files, you can use the --pkg-importer=node
flag to resolve the imports. Here’s an example of how to compile a Sass file using the command line flag:
⬤⬤
sh
JavaScript API
If you are using the JavaScript API to compile your Sass files, you can use the NodePackageImporter()
to resolve the imports. Here’s an example of how to configure the Sass compiler:
⬤⬤
js
Direct URLs
If you cannot use the pkg:
import directive, you can still import the Fontsource stylesheets using the direct URI to the CSS file. Here’s an example of importing the Open Sans font using the direct URL:
⬤⬤
scss
Usage
Once configured, you can import Fontsource stylesheets using the @use
rule in your Sass/SCSS files.
For more advanced usage, you can use the mixins to generate a highly customizable CSS file for your font.