A Vite plugin and family of bundler plugins (Vite, Nuxt, Next.js, Webpack, Rspack) for automatic web font optimization and CJK font splitting. Version 5.1.2 (stable, with recent releases up to 7.6.8 on the underlying cn-font-split engine). Powered by Rust-native cn-font-split for 50% faster builds. Key differentiators: per-project character subsetting for first-screen optimization, automatic WOFF2 conversion, CSS-only approach (no runtime JS), and built-in CLS offset reduction. Supports both full-scale and extremely lightweight optimization modes, with tree-shakeable font info exports. Actively maintained by the Chinese WebFont Project.
npm install vite-plugin-fontVerified import paths — ran on the pinned version, not inferred.
Basic setup for Vite: install plugin, add to config, then import font file as module to get CSS properties and fallback.
Use `Font.vite()` (or `Font.webpack()` for Webpack).
Upgrade to Node.js 18 or later.
Use `import { css } from '...'` and access `css.family`.Destructure: `import { css, fontFamilyFallback } from './font.ttf'`.Run `set CN_FONT_SPLIT_GH_HOST=https://ik.imagekit.io/github` in your terminal before `npm install`.
Run `npm install -D vite-plugin-font` and ensure your project uses ES modules (type: 'module' in package.json or use .mjs).
Use `Font.vite()` (or `Font.webpack()` for Webpack).
Import as: `import { css } from './font.ttf'` (with named exports).Set `CN_FONT_SPLIT_GH_HOST=https://ik.imagekit.io/github` before install.