-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
38 lines (35 loc) · 1.41 KB
/
Copy pathvite.config.js
File metadata and controls
38 lines (35 loc) · 1.41 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
// Production builds ship ONLY the Garda map (the public site); dev serves
// everything. VITE_AREAS overrides either way (VITE_AREAS=halouny,garda
// for a full production build). The logic lives here rather than in the
// Pages workflow so deploy pushes need no `workflow` token scope.
import fs from 'node:fs';
import path from 'node:path';
import { defineConfig } from 'vite';
export default defineConfig(({ command, mode }) => {
// Garda only everywhere — dev included; VITE_AREAS=halouny,garda brings
// the second area back when needed
const areas = process.env.VITE_AREAS ?? 'garda';
const shipped = areas.split(',').map((s) => s.trim()).filter(Boolean);
return {
base: './',
build: { target: 'esnext' },
define: {
// areas.js reads this; '' means all areas (dev default)
'import.meta.env.VITE_AREAS': JSON.stringify(areas),
},
plugins: [{
name: 'prune-unshipped-area-data',
closeBundle() {
if (!shipped.length) return;
const dataDir = path.resolve('dist/data');
if (!fs.existsSync(dataDir)) return;
for (const entry of fs.readdirSync(dataDir, { withFileTypes: true })) {
if (entry.isDirectory() && !shipped.includes(entry.name)) {
fs.rmSync(path.join(dataDir, entry.name), { recursive: true });
console.log(` pruned dist/data/${entry.name} (not shipped)`);
}
}
},
}],
};
});