forked from KlasenK/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
37 lines (28 loc) · 840 Bytes
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { writeFile, readFile } from 'fs/promises';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { existsSync } from 'fs';
async function getStars(): Promise<string> {
// Cache incase something reloads vite config too much
if (existsSync('.stars-cache')) {
return await readFile('.stars-cache', 'utf-8');
}
const res = await fetch('https://api.github.com/repos/gitpod-io/gitpod');
const data = await res.json();
const stars = `${data.stargazers_count ?? 11200}`;
await writeFile('.stars-cache', stars, 'utf-8');
return stars;
}
export default defineConfig({
plugins: [sveltekit()],
resolve: {
preserveSymlinks: true,
},
define: {
__GITHUB_STARS__: await getStars(),
},
build: {
// to resolve https://github.com/vitejs/vite/issues/6985
target: 'esnext',
},
});