diff options
Diffstat (limited to 'subprojects/frontend/config/preloadFontsVitePlugin.ts')
-rw-r--r-- | subprojects/frontend/config/preloadFontsVitePlugin.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/subprojects/frontend/config/preloadFontsVitePlugin.ts b/subprojects/frontend/config/preloadFontsVitePlugin.ts new file mode 100644 index 00000000..bc6f8eaf --- /dev/null +++ b/subprojects/frontend/config/preloadFontsVitePlugin.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import micromatch from 'micromatch'; | ||
2 | import type { PluginOption } from 'vite'; | ||
3 | |||
4 | export default function preloadFontsVitePlugin( | ||
5 | fontsGlob: string | string[], | ||
6 | ): PluginOption { | ||
7 | return { | ||
8 | name: 'refinery-preload-fonts', | ||
9 | apply: 'build', | ||
10 | enforce: 'post', | ||
11 | transformIndexHtml(_html, { bundle }) { | ||
12 | return micromatch(Object.keys(bundle ?? {}), fontsGlob).map((href) => ({ | ||
13 | tag: 'link', | ||
14 | attrs: { | ||
15 | href, | ||
16 | rel: 'preload', | ||
17 | type: 'font/woff2', | ||
18 | as: 'font', | ||
19 | crossorigin: 'anonymous', | ||
20 | }, | ||
21 | })); | ||
22 | }, | ||
23 | }; | ||
24 | } | ||