diff options
author | 2022-12-09 23:49:07 +0100 | |
---|---|---|
committer | 2022-12-11 12:18:43 +0100 | |
commit | 280a3fab74348697429b7bab56b3436968113d79 (patch) | |
tree | e1603153db18f7f35c1bcceb03462409f75002db /subprojects/frontend/config/preloadFontsVitePlugin.ts | |
parent | refactor(frontend): lazy load XtextClient (diff) | |
download | refinery-280a3fab74348697429b7bab56b3436968113d79.tar.gz refinery-280a3fab74348697429b7bab56b3436968113d79.tar.zst refinery-280a3fab74348697429b7bab56b3436968113d79.zip |
refactor(frontend): split vite config
Also introduces tsconfig.shared.json to keep track of source files used
both and build time and in the browser.
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 | } | ||