Skip to content

Commit 4732ce8

Browse files
committed
feat(post-thumbnail): add Vite configs
1 parent 4587aad commit 4732ce8

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

astro.config.mjs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import fs from 'node:fs'
2+
13
import partytown from '@astrojs/partytown'
24
import sitemap from '@astrojs/sitemap'
35
import tailwind from '@astrojs/tailwind'
@@ -29,5 +31,29 @@ export default defineConfig({
2931
sitemap(),
3032
purgecss(),
3133
compress(),
32-
]
34+
],
35+
vite: {
36+
plugins: [rawFonts(['.ttf', '.woff'])],
37+
optimizeDeps: {
38+
exclude: [
39+
'@resvg/resvg-js',
40+
],
41+
},
42+
}
3343
})
44+
45+
// vite plugin to import fonts
46+
function rawFonts(ext) {
47+
return {
48+
name: 'vite-plugin-raw-fonts',
49+
transform(_, id) {
50+
if (ext.some((e) => id.endsWith(e))) {
51+
const buffer = fs.readFileSync(id)
52+
return {
53+
code: `export default ${JSON.stringify(buffer)}`,
54+
map: null,
55+
}
56+
}
57+
},
58+
}
59+
}

0 commit comments

Comments
 (0)