⚡ Webfont 下载 Vite 插件 - 在 Vite 项目中轻松下载和打包 Web 字体。享受隐私优先 - 即使离线 - 使用 persisten
⚡ Webfont 下载 Vite 插件 - 在 Vite 项目中轻松下载和打包 Web 字体。享受隐私优先 - 即使离线 - 使用 persisten
Webfont Download — a Vite plugin that downloads webfonts at build time and self-hosts them, eliminating render-blocking requests to third-party font providers.
The plugin collects webfont links, imports, and definitions from your project, downloads the CSS and font files, adds the fonts to your bundle (or serves them through the dev server), and injects the font definitions using a non-render-blocking method.
Zero config — automatically detects webfont `` tags, plugin config URLs, and CSS @import statements
Self-hosted fonts — font files are bundled with your app; no third-party requests at runtime
Non-render-blocking — fonts are injected as an inline `
Extracts, downloads, and injects fonts from the configured webfont CSS URL(s).
Select your font families at your webfont provider and copy the CSS URL(s) from the "Use on the web" code block:
Pass the CSS URL(s) to the plugin:
// vite.config.js
import webfontDownload from 'vite-plugin-webfont-dl';
export default {
plugins: [
webfontDownload([
'https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap',
'https://fonts.googleapis.com/css2?family=Fira+Code&display=swap',
]),
],
};Whichever method you chose, the result is the same: the webfonts are downloaded, self-hosted, and injected — ready to use on both the local development server and in production builds:
h1 {
font-family: 'Press Start 2P', cursive;
}
h2 {
font-family: 'Fira Code', monospace;
}Import alias: the plugin can be imported under any of these names:
webfontDownload,webfontDl,viteWebfontDl,ViteWebfontDownload, orviteWebfontDownload.
To use with the Laravel Vite Plugin, add this line to your Blade file:
@vite('webfonts.css')
…
**Or**, when using the dev server or the `injectAsStyleTag: false` option:
```html
What happens on the client side:
preload]print stylesheet (non-render-blocking), then promotes it to an all media stylesheet once loaded, by removing the media attribute. [stylesheet]Comparison using a starter Vite project:
| Standard Google Fonts | vite-plugin-webfont-dl |
|---|---|
| webfont.feat.agency | webfont-dl.feat.agency |
| PageSpeed Insights | PageSpeed Insights |
MIT License © 2022–present feat.
暂无开放 Issues,或尚未同步最近议题。