Skip to content

Commit a3dae12

Browse files
chore: update readme and package.json
1 parent 6b742e9 commit a3dae12

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

README.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# unplugin-fonts
22

3-
Universal Webfont loader
3+
㊗️ Universal Webfont loader
4+
5+
[![npm](https://img.shields.io/npm/v/unplugin-fonts.svg)](https://www.npmjs.com/package/unplugin-fonts)
6+
7+
Load fonts from any provider and use them in your project, whatever the framework you use.
8+
9+
This module takes care of loading the font files and generating the font-face rules. By default it preloads the font files and uses the swap strategy, but you can customize this behavior.
10+
11+
Currently supported providers:
12+
- [Typekit](#typekit)
13+
- [Google Fonts](#google-fonts)
14+
- [Custom Fonts](#custom-fonts)
15+
- [Fontsource](#fontsource)
416

517

618
## Install
@@ -156,25 +168,58 @@ import Unfont from 'unplugin-fonts/astro/component.astro';
156168

157169
Example: [`examples/astro`](./examples/astro)
158170

171+
<br></details>
172+
173+
---
174+
175+
176+
<details>
177+
<summary>Migrating from <code>vite-plugin-fonts</code></summary><br>
178+
179+
```diff
180+
// vite.config.ts
181+
-import { VitePluginFonts } from 'vite-plugin-fonts'
182+
+import Unfonts from 'unplugin-fonts/vite'
183+
184+
export default defineConfig({
185+
plugins: [
186+
- VitePluginFonts({
187+
+ Unfonts({
188+
/* options */
189+
}),
190+
],
191+
})
192+
```
193+
194+
195+
```diff
196+
// main.ts
197+
-import 'virtual:fonts.css'
198+
+import 'unfonts.css'
199+
```
200+
201+
159202
<br></details>
160203

161204

162205
## Import generated `@font-rules` CSS
163206

164207
> **Note**
165-
> Required if using local/custom or fontsource fonts
208+
> Required if using **custom** or **fontsource** providers
166209
167210
```ts
168211
import 'unfonts.css'
169212
```
170213

171214

172215

173-
## Options
216+
## Providers
174217

175218

176219
### Typekit
177220

221+
Load fonts from [Typekit](https://typekit.com/).
222+
178223
```ts
179224
Unfonts({
180225
// Typekit API
@@ -204,6 +249,8 @@ Unfonts({
204249

205250
### Google Fonts
206251

252+
Load fonts from [Google Fonts](https://fonts.google.com/).
253+
207254
```ts
208255
Unfonts({
209256
// Google Fonts API V2
@@ -267,6 +314,8 @@ Unfonts({
267314

268315
### Custom Fonts
269316

317+
Load custom fonts from files.
318+
270319
```ts
271320
Unfonts({
272321
// Custom fonts.
@@ -339,6 +388,11 @@ Unfonts({
339388

340389
### Fontsource
341390

391+
Load fonts from [Fontsource](https://fontsource.org/) packages.
392+
393+
> **Note**
394+
> You will need to install `@fontsource/<font>` packages.
395+
342396
```ts
343397
Unfonts({
344398
// Fontsource API

examples/vite/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ h2 {
2222
font-family: "ABeeZee", sans-serif;
2323
}
2424

25-
. {
25+
.fontsource-truculenta {
2626
font-family: "Truculenta", sans-serif;
2727
}

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
"name": "unplugin-fonts",
33
"version": "1.0.0-beta.0",
44
"description": "Universal Webfont loader",
5-
"author": "stafyniaksacha",
5+
"author": {
6+
"name": "cssninjaStudio <[email protected]> (https://cssninja.io)"
7+
},
68
"license": "MIT",
7-
"repository": "stafyniaksacha/unplugin-fonts",
9+
"repository": "cssninjaStudio/unplugin-fonts",
810
"keywords": [
911
"fonts",
12+
"google-fonts",
13+
"typekit",
14+
"fontsource",
15+
"webfontloader",
1016
"svelte",
1117
"nuxt",
1218
"vite",

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export default createUnplugin<Options | undefined>((userOptions) => {
2828

2929
load(id) {
3030
if (id.startsWith(resolvedVirtualModuleId)) {
31-
const s = new MagicString(`export const links = ${JSON.stringify(getHeadLinkTags(options, root))};\n`)
31+
const tags = getHeadLinkTags(options, root)
32+
const s = new MagicString(`export const links = ${JSON.stringify(tags)};\n`)
3233

3334
return {
3435
code: s.toString(),

0 commit comments

Comments
 (0)