Migrate to vite
All checks were successful
Check & deploy / validate (push) Successful in 3m0s
Check & deploy / deploy (push) Successful in 55s

This commit is contained in:
Andras Schmelczer 2026-05-31 13:23:10 +01:00
parent 1914991250
commit 5bdf68eabd
10 changed files with 611 additions and 56 deletions

58
vite.config.ts Normal file
View file

@ -0,0 +1,58 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { defineConfig, type Plugin } from 'vite';
const SITE_URL = 'https://schmelczer.dev/photos/';
const readGallerySection = (name: string): string => {
try {
const html = readFileSync(
resolve(__dirname, 'src/generated/gallery.html'),
'utf8'
);
const match = html.match(
new RegExp(`<!-- ${name} -->([\\s\\S]*?)<!-- /${name} -->`)
);
return match?.[1]?.trim() ?? '';
} catch {
return '';
}
};
const generatedGalleryPlugin = (): Plugin => ({
name: 'generated-gallery',
transformIndexHtml(html) {
const ogImageUrl = new URL('og-image.jpg', SITE_URL).toString();
return html
.replaceAll('__SITE_URL__', SITE_URL)
.replaceAll('__OG_IMAGE_URL__', ogImageUrl)
.replace('<!-- gallery:portraits -->', readGallerySection('portraits'))
.replace('<!-- gallery:frame -->', readGallerySection('frame'))
.replace('<!-- gallery:landscapes -->', readGallerySection('landscapes'));
},
});
export default defineConfig({
base: './',
root: 'src',
publicDir: '../public',
build: {
outDir: '../dist',
emptyOutDir: true,
assetsDir: 'assets',
sourcemap: false,
},
server: {
host: '127.0.0.1',
port: 5173,
strictPort: false,
},
preview: {
host: '127.0.0.1',
port: 4173,
strictPort: false,
},
plugins: [generatedGalleryPlugin()],
});