Closed thonkinator closed 1 year ago
Hi @thonkinator!
I've tried to test what's happening on your side, here what I did:
npm i vite-plugin-webfont-dl -D
import webfontDownload from 'vite-plugin-webfont-dl'
and webfontDownload()
to plugins
array (in vite.config.ts
)index.html
:
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400&family=Roboto:wght@100&display=swap" rel="stylesheet">
font-family
to Roboto
in src/app.css
In this way the web server is working as expected, there's a virtual route (/@webfonts/webfonts.css
), containing virtual font definitions, which are downloaded JIT as requested.
Link to my fork: https://stackblitz.com/edit/vitejs-vite-zsqx2t?file=package.json,vite.config.ts,index.html,src%2Fapp.css&terminal=dev
Could you please send link to your project or a sample which showing it's not working?
@0xb4lint I was using the feature where you could add the webfont URLs to vite.config.ts, but I'll try adding the actual <link>
elements when I get home. Thanks!
I've made another fork using the configuration option instead of <link>
s:
https://stackblitz.com/edit/vitejs-vite-bzfrca?file=package.json,vite.config.ts,src%2Fapp.css&terminal=dev
It works with dev server and build as well.
Wasn't he talking about SvelteKit? Your forks do not use SvelteKit, only Svelte and Vite.
Wasn't he talking about SvelteKit? Your forks do not use SvelteKit, only Svelte and Vite.
You are right @phiberber!
I've just checked with a new SvelteKit project, unfortunately neither the transformIndexHtml
hook nor the transform
hook was called with any html input. That means the plugin cannot read or inject to the app.html
file. 😞
I've tried to use vite-plugin-webfont-dl in my SvelteKit project, but nothing seems to be injected. The
/webfonts.css
route is created and does work, but there are no<link>
elements added to<head>
or any CSS@import
statements.