-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
76 lines (69 loc) · 2.16 KB
/
Copy pathvite.config.js
File metadata and controls
76 lines (69 loc) · 2.16 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
64
65
66
67
68
69
70
71
72
73
74
75
76
import { defineConfig } from 'vite';
import { readdirSync, existsSync } from 'node:fs';
import { execSync } from 'node:child_process';
import { resolve } from 'node:path';
const VERSIONS_DIR = resolve(__dirname, 'versions');
const MANIFEST = resolve(VERSIONS_DIR, 'manifest.json');
const GEN_SCRIPT = resolve(__dirname, 'scripts/gen-overview.mjs');
function regenerateOverview() {
execSync(`node "${GEN_SCRIPT}"`, { cwd: __dirname, stdio: 'inherit' });
}
regenerateOverview();
const VARIANT_PAGES = ['index.html', 'impressum.html', 'datenschutz.html'];
const versionEntries = Object.fromEntries(
readdirSync(VERSIONS_DIR, { withFileTypes: true })
.filter((d) => d.isDirectory() && /^v\d+/.test(d.name))
.flatMap((d) =>
VARIANT_PAGES
.map((page) => {
const full = resolve(VERSIONS_DIR, d.name, page);
if (!existsSync(full)) return null;
const key = page === 'index.html' ? d.name : `${d.name}-${page.replace(/\.html$/, '')}`;
return [key, full];
})
.filter(Boolean)
)
);
const overviewRegenPlugin = {
name: 'schlenkr-overview-regen',
configureServer(server) {
const trigger = () => {
try {
regenerateOverview();
server.ws.send({ type: 'full-reload', path: '*' });
} catch (e) {
server.config.logger.error(`[overview-regen] ${e.message}`);
}
};
server.watcher.add(MANIFEST);
server.watcher.on('change', (file) => {
if (file === MANIFEST) trigger();
});
server.watcher.on('add', (file) => {
if (file.startsWith(VERSIONS_DIR) && file.endsWith('/index.html')) trigger();
});
server.watcher.on('unlink', (file) => {
if (file.startsWith(VERSIONS_DIR) && file.endsWith('/index.html')) trigger();
});
}
};
export default defineConfig(({ command }) => ({
root: 'versions',
base: command === 'build' ? '/schlenkr/' : '/',
plugins: [overviewRegenPlugin],
server: {
port: 8080,
open: '/',
strictPort: true
},
build: {
outDir: '../dist',
emptyOutDir: true,
rollupOptions: {
input: {
index: resolve(VERSIONS_DIR, 'index.html'),
...versionEntries
}
}
}
}));