-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
79 lines (74 loc) · 2.03 KB
/
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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { fileURLToPath, URL } from 'node:url';
import { execSync } from 'node:child_process';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { Mode, plugin as markdown } from 'vite-plugin-markdown';
import markdownit from 'markdown-it';
import anchor from 'markdown-it-anchor';
const KUBECTL_PROXY = 'http://127.0.0.1:8001';
const getVersion = () => execSync('git describe --always --dirty').toString().trimEnd();
let version = getVersion();
const modulesWithVersions = new Map();
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
markdown({
mode: [Mode.VUE],
markdownIt: markdownit({ html: true }).use(anchor),
}),
{
name: 'app-version',
handleHotUpdate: ({ server }) => {
const v = getVersion();
if (version !== v) {
version = v;
[...modulesWithVersions.keys()].forEach((id) => {
const module = server.moduleGraph.idToModuleMap.get(id);
if (module) {
server.reloadModule(module);
} else {
modulesWithVersions.delete(id);
}
});
}
},
transform: (code, id) => ({
code: code.replace(/__version_placeholder__/g, () => {
modulesWithVersions.set(id, null);
return version;
}),
map: null,
}),
},
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
build: {
target: 'es2023',
reportCompressedSize: false,
},
experimental: {
renderBuiltUrl: (filename: string, { hostType }: { hostType: 'js' | 'css' | 'html' }) => {
if (hostType === 'js') {
return { runtime: `window.__base_url + ${JSON.stringify(filename)}` };
} else {
return { relative: true };
}
},
},
server: {
proxy: {
'/openapi': KUBECTL_PROXY,
'/api': {
target: KUBECTL_PROXY,
ws: true,
},
'/apis': KUBECTL_PROXY,
'/version': KUBECTL_PROXY,
},
},
});