-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
53 lines (49 loc) · 1.5 KB
/
Copy pathvite.config.js
File metadata and controls
53 lines (49 loc) · 1.5 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
import { defineConfig } from 'vite';
import fs from 'node:fs';
import path from 'node:path';
// Build-time manifest of the photos in /public/<category>/.
// They are served as stable, cacheable URLs at /<category>/<file> (dev + build)
// — good for SEO/caching — and are NOT re-bundled/duplicated by Vite.
function galleryManifest() {
const virtualId = 'virtual:gallery';
const resolvedId = '\0' + virtualId;
const categories = ['smjestaj', 'vlasic', 'travnik'];
const build = () => {
const pub = path.resolve(process.cwd(), 'public');
const data = {};
for (const cat of categories) {
let files = [];
try {
files = fs
.readdirSync(path.join(pub, cat))
.filter((f) => /\.(jpe?g|png)$/i.test(f))
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
} catch {
files = [];
}
data[cat] = files.map((f) => `/${cat}/${f}`);
}
return data;
};
return {
name: 'vikendica-gallery-manifest',
resolveId(id) {
if (id === virtualId) return resolvedId;
},
load(id) {
if (id === resolvedId) {
return `export const manifest = ${JSON.stringify(build())};`;
}
},
};
}
export default defineConfig({
plugins: [galleryManifest()],
server: {
// Honour a PORT assigned by the environment (e.g. preview harness),
// otherwise default to Vite's 5173.
port: process.env.PORT ? Number(process.env.PORT) : 5173,
open: false,
},
build: { outDir: 'dist' },
});