Skip to content

Commit 8ccd009

Browse files
fix: google fonts style encoding + make vite a peer dependencies
1 parent 342a6b6 commit 8ccd009

File tree

8 files changed

+50
-55
lines changed

8 files changed

+50
-55
lines changed

example/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
"dev": "vite",
66
"build": "vite build"
77
},
8-
"dependencies": {
9-
"vite-plugin-fonts": "workspace: *"
10-
},
118
"devDependencies": {
12-
"vite": "^2.0.0-beta.5"
9+
"vite": "^2.0.0-beta.22",
10+
"vite-plugin-fonts": "workspace: *"
1311
}
1412
}

example/style.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
body {
2-
font-family: 'Crimson Pro', Avenir, Helvetica, Arial, sans-serif;
2+
font-family: "Crimson Pro", Avenir, Helvetica, Arial, sans-serif;
33
-webkit-font-smoothing: antialiased;
44
-moz-osx-font-smoothing: grayscale;
55
text-align: center;
@@ -8,5 +8,5 @@ body {
88
}
99

1010
a {
11-
font-family: 'Open Sans', Avenir, Helvetica, Arial, sans-serif;
12-
}
11+
font-family: "Open Sans", Avenir, Helvetica, Arial, sans-serif;
12+
}

example/vite.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { defineConfig } from 'vite'
2-
import ViteFonts from 'vite-plugin-fonts';
2+
import ViteFonts from 'vite-plugin-fonts'
33

44
export default defineConfig({
55
plugins: [
66
ViteFonts({
77
google: {
88
families: ['Crimson Pro', 'Open Sans'],
99
},
10-
})
11-
]
12-
})
10+
}),
11+
],
12+
})

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"lint": "eslint --ext .ts ./src",
2020
"lint:fix": "eslint --fix --ext .ts ./src"
2121
},
22-
"dependencies": {
23-
"vite": "^2.0.0-beta.5"
22+
"peerDependencies": {
23+
"vite": "^2.0.0-beta.22"
2424
},
2525
"devDependencies": {
2626
"@antfu/eslint-config": "^0.4.3",
2727
"@typescript-eslint/eslint-plugin": "^4.12.0",
2828
"eslint": "^7.17.0",
2929
"tsup": "^3.11.0",
30-
"typescript": "^4.1.3"
30+
"typescript": "^4.1.3",
31+
"vite": "^2.0.0-beta.22"
3132
}
3233
}

pnpm-lock.yaml

Lines changed: 20 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google-fonts.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function injectFonts({
5454
let spec = encodeURIComponent(name)
5555

5656
if (typeof styles === 'string')
57-
spec += `:${encodeURIComponent(styles)}`
57+
spec += `:${styles}`
5858

5959
if (defer)
6060
deferedSpecs.push(spec)
@@ -64,15 +64,16 @@ function injectFonts({
6464
}
6565

6666
// warm up the fonts’ origin
67-
if (preconnect && specs.length + deferedSpecs.length > 0)
67+
if (preconnect && specs.length + deferedSpecs.length > 0) {
6868
tags.push({
6969
tag: 'link',
7070
attrs: {
7171
rel: 'preconnect',
7272
href: 'https://fonts.gstatic.com/',
73-
crossorigin: '',
74-
}
73+
crossorigin: true,
74+
},
7575
})
76+
}
7677

7778
// defer loading font-faces definitions
7879
// @see https://web.dev/optimize-lcp/#defer-non-critical-css
@@ -90,9 +91,9 @@ function injectFonts({
9091
attrs: {
9192
rel: 'preload',
9293
as: 'style',
93-
onload: "this.rel='stylesheet'",
94+
onload: 'this.rel=\'stylesheet\'',
9495
href,
95-
}
96+
},
9697
})
9798
}
9899

@@ -111,7 +112,7 @@ function injectFonts({
111112
attrs: {
112113
rel: 'stylesheet',
113114
href,
114-
}
115+
},
115116
})
116117
}
117118

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ function VitePluginFonts(options: VitePluginFontsOptions = {}) {
1414

1515
transformIndexHtml(): HtmlTagDescriptor[] {
1616
const tags: HtmlTagDescriptor[] = []
17-
17+
1818
if (options.typekit)
1919
tags.push(...injectTypekitFonts(options.typekit))
2020

2121
if (options.google)
2222
tags.push(...injectGoogleFonts(options.google))
2323

24-
return tags;
24+
return tags
2525
},
2626
}
2727
}

src/typekit.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@ function injectFonts({
1919
return tags
2020
}
2121

22-
if (defer)
22+
if (defer) {
2323
tags.push({
2424
tag: 'link',
2525
attrs: {
2626
rel: 'preload',
2727
as: 'style',
28-
onload: "this.rel='stylesheet'",
28+
onload: 'this.rel=\'stylesheet\'',
2929
href: `${TypekitFontBase}${id}.css`,
30-
}
30+
},
3131
})
32-
else
32+
}
33+
else {
3334
tags.push({
3435
tag: 'link',
3536
attrs: {
3637
rel: 'stylesheet',
3738
href: `${TypekitFontBase}${id}.css`,
38-
}
39+
},
3940
})
41+
}
4042

4143
return tags
4244
}

0 commit comments

Comments
 (0)