Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Latest commit

 

History

History
80 lines (61 loc) · 1.5 KB

readme.md

File metadata and controls

80 lines (61 loc) · 1.5 KB

postcss-webfontloader

Provides fallbacks for loading fonts with Web Font Loader.


Deprecated: Google Fonts started offering stylesheets with font-display: swap, which has a decent browser support, so you might want to consider using that instead of mimicking the same behavior by loading fonts with Web Font Loader and generating fallbacks using this PostCSS plugin.


Setup

yarn add postcss-webfontloader
// postcss.config.js
module.exports = {
  plugins: {
    'postcss-webfontloader': {
      modules: false,
      families: [
        'Lora',
      ],
    },
  },
}

Basic usage

Input

/* base.css */
body {
  font-family: Lora, Georgia, serif;
}

h1, h2, h3, h4, h5, h6 {
  font-family: "Helvetica Neue", Helvetica, sans-serif;
}

Output

/* base.css */
body {
  font-family: Georgia, serif;
}
.wf-active body {
  font-family: Lora, Georgia, serif;
}

h1, h2, h3, h4, h5, h6 {
  font-family: "Helvetica Neue", Helvetica, sans-serif;
}

Output for CSS Modules

If you're using CSS Modules, set modules to true to get the following output:

/* base.css */
body {
  font-family: Georgia, serif;
}
:global(.wf-active) body {
  font-family: Lora, Georgia, serif;
}

h1, h2, h3, h4, h5, h6 {
  font-family: "Helvetica Neue", Helvetica, sans-serif;
}