-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
63 lines (59 loc) · 1.62 KB
/
Copy pathvite.config.ts
File metadata and controls
63 lines (59 loc) · 1.62 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @file vite.config.ts
* @description Configuration for Vite bundler.
*/
import path from 'path';
import { fileURLToPath } from 'url';
import { defineConfig, loadEnv, Plugin } from 'vite';
import svgr from 'vite-plugin-svgr';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default defineConfig(({ mode }: { mode: string }) => {
const env = loadEnv(mode, '.', '');
const plugins: Array<Plugin> = [svgr()];
if (mode !== 'production' && env.GEMINI_API_KEY) {
const injectGeminiKey = (): Plugin => ({
name: 'inject-gemini-key',
transformIndexHtml(html) {
const jsonKey = JSON.stringify(env.GEMINI_API_KEY);
return html.replace(
'</head>',
`<script>window.GEMINI_API_KEY=${jsonKey};localStorage.setItem('whispersInTheDark_geminiApiKey',${jsonKey});</script></head>`,
);
},
});
plugins.push(injectGeminiKey());
}
return {
plugins,
base: "/Whispers-in-the-Dark/",
define: {},
resolve: {
alias: {
'@': path.resolve(__dirname, '.'),
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('genai')) {
return 'gemini';
}
if (id.includes('node_modules')) {
return 'vendor';
}
if (id.includes('debug')) {
return 'debug';
}
if (id.includes('resources')) {
return 'resources';
}
if (id.includes('hooks')) {
return 'hooks';
}
},
},
},
},
};
});