[PR #262] [CLOSED] feat(font): replace generated font catalog with Vite import-rewriting transform #425

Closed
opened 2026-05-06 12:39:44 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/262
Author: @yunus25jmi1
Created: 3/5/2026
Status: Closed

Base: mainHead: feat/font-vite-transform


📝 Commits (3)

  • 8c1d17f feat(font): replace generated font catalog with Vite import-rewriting transform
  • d977bc8 Merge origin/main into feat/font-vite-transform - resolve conflicts
  • 4ec675c fix: apply oxfmt formatting after merge with main

📊 Changes

9 files changed (+343 additions, -2437 deletions)

View changed files

📝 CLAUDE.md (+1 -1)
📝 packages/vinext/src/index.ts (+215 -102)
📝 packages/vinext/src/shims/font-google-base.ts (+4 -3)
packages/vinext/src/shims/font-google.generated.ts (+0 -2251)
📝 packages/vinext/src/shims/font-google.ts (+1 -1)
📝 packages/vinext/src/shims/next-shims-font-google.generated.d.ts (+1 -0)
📝 scripts/generate-google-fonts.js (+1 -17)
📝 tests/font-google.test.ts (+108 -57)
📝 tests/shims.test.ts (+12 -5)

📄 Description

Summary

Closes #200

Instead of a 1928-line generated font catalog (font-google.generated.ts) that re-exports every Google Font as a createFontLoader call, the vinext:google-fonts Vite plugin now rewrites next/font/google import statements at compile time.

Before

// font-google.generated.ts (1928 lines, ~70KB)
export const Inter: FontLoader = createFontLoader('Inter');
export const Roboto: FontLoader = createFontLoader('Roboto');
// ... 1926 more lines

After

The plugin rewrites imports at compile time across all Vite environments (RSC, SSR, client):

// User writes:
import { Inter, Roboto_Mono } from 'next/font/google'

// Plugin transforms to:
import { createFontLoader as __vinext_clf } from 'next/font/google';
const Inter = __vinext_clf('Inter');
const Roboto_Mono = __vinext_clf('Roboto Mono');

Self-hosted font fetching during production builds continues to work as before.

Changes

  • Delete packages/vinext/src/shims/font-google.generated.ts (1928 lines / ~70 KB)
  • Update font-google.ts to export createFontLoader instead of re-exporting the catalog
  • Add createFontLoader export to next-shims-font-google.generated.d.ts for IDE autocomplete
  • Rewrite vinext:google-fonts Vite plugin to perform import-time transforms in dev + build
  • Fix Proxy in font-google-base.ts to handle underscore-style names (Roboto_Mono'Roboto Mono') for users who skip the Vite plugin
  • Update generate-google-fonts.js to only generate .d.ts (no longer generates .ts catalog)
  • Update tests to use createFontLoader API instead of named exports

Testing

  • All 54 font-google.test.ts tests pass
  • All 7 font/google tests in shims.test.ts pass
  • All 9 entry-templates.test.ts tests pass

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/262 **Author:** [@yunus25jmi1](https://github.com/yunus25jmi1) **Created:** 3/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/font-vite-transform` --- ### 📝 Commits (3) - [`8c1d17f`](https://github.com/cloudflare/vinext/commit/8c1d17f11dde9c233a27bcedd70417fab733c744) feat(font): replace generated font catalog with Vite import-rewriting transform - [`d977bc8`](https://github.com/cloudflare/vinext/commit/d977bc8cc596c68de8bdc752c7f319819715b18e) Merge origin/main into feat/font-vite-transform - resolve conflicts - [`4ec675c`](https://github.com/cloudflare/vinext/commit/4ec675cfb7a832726815328a82d4040c90e53c35) fix: apply oxfmt formatting after merge with main ### 📊 Changes **9 files changed** (+343 additions, -2437 deletions) <details> <summary>View changed files</summary> 📝 `CLAUDE.md` (+1 -1) 📝 `packages/vinext/src/index.ts` (+215 -102) 📝 `packages/vinext/src/shims/font-google-base.ts` (+4 -3) ➖ `packages/vinext/src/shims/font-google.generated.ts` (+0 -2251) 📝 `packages/vinext/src/shims/font-google.ts` (+1 -1) 📝 `packages/vinext/src/shims/next-shims-font-google.generated.d.ts` (+1 -0) 📝 `scripts/generate-google-fonts.js` (+1 -17) 📝 `tests/font-google.test.ts` (+108 -57) 📝 `tests/shims.test.ts` (+12 -5) </details> ### 📄 Description ## Summary Closes #200 Instead of a 1928-line generated font catalog (`font-google.generated.ts`) that re-exports every Google Font as a `createFontLoader` call, the `vinext:google-fonts` Vite plugin now rewrites `next/font/google` import statements at compile time. ### Before ```ts // font-google.generated.ts (1928 lines, ~70KB) export const Inter: FontLoader = createFontLoader('Inter'); export const Roboto: FontLoader = createFontLoader('Roboto'); // ... 1926 more lines ``` ### After The plugin rewrites imports at compile time across all Vite environments (RSC, SSR, client): ```ts // User writes: import { Inter, Roboto_Mono } from 'next/font/google' // Plugin transforms to: import { createFontLoader as __vinext_clf } from 'next/font/google'; const Inter = __vinext_clf('Inter'); const Roboto_Mono = __vinext_clf('Roboto Mono'); ``` Self-hosted font fetching during production builds continues to work as before. ## Changes - **Delete** `packages/vinext/src/shims/font-google.generated.ts` (1928 lines / ~70 KB) - Update `font-google.ts` to export `createFontLoader` instead of re-exporting the catalog - Add `createFontLoader` export to `next-shims-font-google.generated.d.ts` for IDE autocomplete - Rewrite `vinext:google-fonts` Vite plugin to perform import-time transforms in dev + build - Fix Proxy in `font-google-base.ts` to handle underscore-style names (`Roboto_Mono` → `'Roboto Mono'`) for users who skip the Vite plugin - Update `generate-google-fonts.js` to only generate `.d.ts` (no longer generates `.ts` catalog) - Update tests to use `createFontLoader` API instead of named exports ## Testing - All 54 `font-google.test.ts` tests pass - All 7 font/google tests in `shims.test.ts` pass - All 9 `entry-templates.test.ts` tests pass --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:44 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#425
No description provided.