Skip to content

Commit 909c1f4

Browse files
fix: expose typescript declaration
1 parent f992a07 commit 909c1f4

File tree

8 files changed

+41
-18
lines changed

8 files changed

+41
-18
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ import 'unfonts.css'
147147
```
148148

149149

150+
150151
## Options
151152

152153

@@ -366,6 +367,15 @@ Unfonts({
366367
})
367368
```
368369

370+
## Typescript Definitions
371+
372+
```json
373+
{
374+
"compilerOptions": {
375+
"types": ["unplugin-fonts/client"]
376+
}
377+
}
378+
```
369379

370380
## Ressources
371381

client.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare module 'unfonts.css' {
2+
const content: string
3+
export default content
4+
}
5+
6+
declare module 'unplugin-fonts/head' {
7+
export const links: string[]
8+
}

examples/nuxt/app.vue

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<script setup lang="ts">
2-
// @ts-ignore
3-
import { tags } from 'unplugin-fonts/head'
2+
import { links } from 'unplugin-fonts/head'
3+
import src from 'unfonts.css'
44
</script>
55

66
<template>
77
<h1>Hello Nuxt!</h1>
88
<h2>I'm using a local font !</h2>
9-
<pre>{{ tags }}</pre>
9+
<pre>links: {{ links }}</pre>
10+
<pre>src: {{ src }}</pre>
1011
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
1112
</template>
1213

1314
<style>
14-
body {
15+
:root {
1516
font-family: "Crimson Pro", Avenir, Helvetica, Arial, sans-serif;
1617
-webkit-font-smoothing: antialiased;
1718
-moz-osx-font-smoothing: grayscale;
@@ -24,6 +25,10 @@ a {
2425
font-family: "Open Sans", Avenir, Helvetica, Arial, sans-serif;
2526
}
2627
28+
pre {
29+
text-align: left;
30+
}
31+
2732
h2 {
2833
font-family: "Dancing Script", sans-serif;
2934
font-size: 3rem;

examples/nuxt/nuxt.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default defineNuxtConfig({
44
modules: [
55
Unfonts,
66
],
7-
fonts: {
7+
unfonts: {
88
google: {
99
families: ['Crimson Pro', 'Open Sans', 'Material+Icons'],
1010
},

examples/nuxt/tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
// https://nuxt.com/docs/guide/concepts/typescript
3-
"extends": "./.nuxt/tsconfig.json"
3+
"extends": "./.nuxt/tsconfig.json",
4+
"compilerOptions": {
5+
"types": ["unplugin-fonts/client"]
6+
}
47
}

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"types": "./dist/astro/component.d.ts",
2121
"import": "./dist/astro/component.astro"
2222
},
23-
"./head": {
24-
"types": "./dist/head.d.ts"
25-
},
2623
"./esbuild": {
2724
"types": "./dist/esbuild.d.ts",
2825
"require": "./dist/esbuild.js",
@@ -53,6 +50,9 @@
5350
"require": "./dist/webpack.js",
5451
"import": "./dist/webpack.mjs"
5552
},
53+
"./client": {
54+
"types": "./client.d.ts"
55+
},
5656
"./*": "./*"
5757
},
5858
"main": "dist/index.js",
@@ -67,7 +67,8 @@
6767
}
6868
},
6969
"files": [
70-
"dist"
70+
"dist",
71+
"client.d.ts"
7172
],
7273
"scripts": {
7374
"build": "tsup",

src/head.ts

-4
This file was deleted.

src/nuxt.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import unplugin from '.'
99
export default defineNuxtModule({
1010
meta: {
1111
name: 'unplugin-fonts',
12-
configKey: 'fonts',
12+
configKey: 'unfonts',
1313
},
1414
setup(options: Options, nuxt) {
15-
nuxt.options.css ??= []
15+
nuxt.options.css ||= []
1616
nuxt.options.css.push('unfonts.css')
1717

1818
const links = getHeadLinkTags(options, nuxt.options.rootDir)
1919

20-
nuxt.options.app.head ??= {}
21-
nuxt.options.app.head.link ??= []
20+
nuxt.options.app.head ||= {}
21+
nuxt.options.app.head.link ||= []
2222

2323
for (const link of links) {
2424
nuxt.options.app.head.link.push({

0 commit comments

Comments
 (0)