49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import react from '@vitejs/plugin-react';
|
|
import { fileURLToPath, URL } from 'node:url';
|
|
import { defineConfig, type UserConfig } from 'vite';
|
|
|
|
/**
|
|
* Funktionsform, damit ein Produktionsbau (Gitea-Runner) nichts vom
|
|
* Entwicklungsserver anfasst. Der Bau erzeugt ausschliesslich statische
|
|
* Dateien; auf dem Zielsystem laeuft kein Node.
|
|
*/
|
|
export default defineConfig(({ command }) => {
|
|
const config: UserConfig = {
|
|
plugins: [react()],
|
|
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
build: {
|
|
outDir: 'dist',
|
|
// Quellkarten bleiben aus: das Buendel liegt auf einem erreichbaren
|
|
// nginx und soll den Quelltext nicht mitliefern.
|
|
sourcemap: false,
|
|
target: 'es2022',
|
|
rollupOptions: {
|
|
output: {
|
|
// React getrennt halten, damit ein Oberflaechen-Update nicht
|
|
// den gesamten Cache der Anwender entwertet.
|
|
manualChunks: { react: ['react', 'react-dom'] },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
// Ab hier nur noch Entwicklungsserver. Ein `vite build` erreicht diese
|
|
// Zeilen nie und braucht deshalb weder Proxy noch laufendes Backend.
|
|
if (command !== 'serve') return config;
|
|
|
|
config.server = {
|
|
port: 5173,
|
|
strictPort: true,
|
|
proxy: {
|
|
// Im Betrieb macht das nginx. Lokal zeigt der Proxy auf
|
|
// `php -S 127.0.0.1:8080 -t backend/public`.
|
|
'/api': {
|
|
target: process.env.EKDOS_BACKEND ?? 'http://127.0.0.1:8080',
|
|
changeOrigin: false,
|
|
},
|
|
},
|
|
};
|
|
|
|
return config;
|
|
});
|