TomerAberbach / postcss-fontpie

A PostCSS plugin for optimizing font loading layout shifts using fontpie!
https://npm.im/postcss-fontpie
Apache License 2.0
51 stars 2 forks source link

Add option to suppress 'Missing font type mapping' warnings #6

Closed kripod closed 1 year ago

kripod commented 1 year ago

While trying to integrate this plugin in an Astro project, the parameter provided by srcUrlToFilename couldn’t be used, as sometimes, the url has a format similar to .__VITE_ASSET__abcd1234__.

In order to mitigate the issue, I came up with the idea of including the plugin twice and returning a static path via srcUrlToFilename. However, the following postcss.config.cjs produces unwanted 'Missing font type mapping' warnings as a result:

const postcssFontpie = require("postcss-fontpie");

const atkinsonHyperlegibleFilename = require.resolve(
  "@fontsource/atkinson-hyperlegible/files/atkinson-hyperlegible-latin-400-normal.woff2",
);
const jetBrainsMonoFilename = require.resolve(
  "@fontsource/jetbrains-mono/files/jetbrains-mono-latin-400-normal.woff2",
);

module.exports = {
  plugins: [
    postcssFontpie({
      fontTypes: { "Atkinson Hyperlegible": "sans-serif" },
      srcUrlToFilename: () => atkinsonHyperlegibleFilename,
    }),
    postcssFontpie({
      fontTypes: { "JetBrains Mono": "mono" },
      srcUrlToFilename: () => jetBrainsMonoFilename,
    }),
  ],
};

I’d propose an option to suppress such warnings as a mitigation.

TomerAberbach commented 1 year ago

Gonna implement #7 instead