This plugin can automatically inject google font tags into your HTML.
Step 1: Install the package.
npm install vite-plugin-gfont -D
Step 2: Import it to your vite configuration.
import gfont from 'vite-plugin-gfont';
export default defineConfig({
plugins: [gfont({
proxy: '', // use proxy for google font
fonts: [
{
family: 'Roboto',
styles: [
400,
{
weight: 500,
italic: true,
},
]; // weight or {weight, italic}, optional.
},
],
display: 'swap', // https://developer.mozilla.org/en-US/docs/Web/API/FontFace/display
})],
});
MIT