feat: migrate to Astro's experimental font API

Replace @fontsource-variable NPM packages with Astro's built-in
experimental font API using the Fontsource provider. Fonts are now
fetched at build time, cached locally, and served with the site.

This provides automatic @font-face generation, preload link injection,
and metric-adjusted fallback fonts (size-adjust, ascent-override, etc.)
to reduce CLS during font loading.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-01 02:43:48 +00:00
parent e85a83c2c6
commit e5d2604edc
5 changed files with 119 additions and 70 deletions

View File

@@ -1,4 +1,4 @@
import { defineConfig } from "astro/config";
import { defineConfig, fontProviders } from "astro/config";
import tailwindcss from "@tailwindcss/vite";
import sitemap from "@astrojs/sitemap";
import icon from "astro-icon";
@@ -10,4 +10,29 @@ export default defineConfig({
vite: {
plugins: [tailwindcss()],
},
experimental: {
fonts: [
{
provider: fontProviders.fontsource(),
name: "Bricolage Grotesque",
cssVariable: "--font-bricolage",
weights: ["200 800"],
fallbacks: ["system-ui", "sans-serif"],
},
{
provider: fontProviders.fontsource(),
name: "DM Sans",
cssVariable: "--font-dm-sans",
weights: ["100 1000"],
fallbacks: ["system-ui", "sans-serif"],
},
{
provider: fontProviders.fontsource(),
name: "JetBrains Mono",
cssVariable: "--font-jetbrains",
weights: ["100 800"],
fallbacks: ["SF Mono", "Consolas", "monospace"],
},
],
},
});