Files
govoplan-core/webui/vite.config.ts
Albrecht Degering 94236a7d7e
Some checks failed
Dependency Audit / dependency-audit (push) Failing after 50s
Module Matrix / module-matrix (push) Failing after 49s
Prepare GovOPlaN self-hosted release workflow
2026-07-10 21:57:22 +02:00

118 lines
4.3 KiB
TypeScript

import { existsSync } from "node:fs";
import { createRequire } from "node:module";
import { dirname, join } from "node:path";
import { fileURLToPath, URL } from "node:url";
import { defineConfig, type Plugin } from "vite";
import react from "@vitejs/plugin-react";
const require = createRequire(import.meta.url);
const webuiRoot = dirname(fileURLToPath(import.meta.url));
const installedModulesVirtualId = "virtual:govoplan-installed-modules";
const resolvedInstalledModulesVirtualId = `\0${installedModulesVirtualId}`;
const defaultWebModulePackages = [
"@govoplan/access-webui",
"@govoplan/admin-webui",
"@govoplan/calendar-webui",
"@govoplan/campaign-webui",
"@govoplan/dashboard-webui",
"@govoplan/docs-webui",
"@govoplan/files-webui",
"@govoplan/idm-webui",
"@govoplan/mail-webui",
"@govoplan/organizations-webui",
"@govoplan/ops-webui"
];
function configuredWebModulePackages(): string[] {
const configured = process.env.GOVOPLAN_WEBUI_MODULE_PACKAGES;
if (configured === undefined) return defaultWebModulePackages;
return configured.split(",").map((specifier) => specifier.trim()).filter(Boolean);
}
function packageDirectory(specifier: string): string {
const parts = specifier.startsWith("@") ? specifier.split("/") : [specifier];
return join(webuiRoot, "node_modules", ...parts);
}
function packageInstalled(specifier: string): boolean {
if (existsSync(join(packageDirectory(specifier), "package.json"))) return true;
try {
require.resolve(specifier);
return true;
} catch {
return false;
}
}
function availableWebModuleSpecifiers(): string[] {
return configuredWebModulePackages().filter(packageInstalled);
}
function govoplanInstalledModulesPlugin(): Plugin {
return {
name: "govoplan-installed-modules",
resolveId(id: string) {
if (id === installedModulesVirtualId) return resolvedInstalledModulesVirtualId;
return null;
},
load(id: string) {
if (id !== resolvedInstalledModulesVirtualId) return null;
const imports = availableWebModuleSpecifiers();
return [
...imports.map((specifier, index) => `import module${index} from ${JSON.stringify(specifier)};`),
`export const installedWebModules = [${imports.map((_specifier, index) => `module${index}`).join(", ")}];`,
"export default installedWebModules;"
].join("\n");
}
};
}
export default defineConfig({
plugins: [govoplanInstalledModulesPlugin(), react()],
optimizeDeps: {
exclude: availableWebModuleSpecifiers()
},
build: {
// Full-product builds include the host shell plus all installed module wiring.
// Dedicated route/vendor splitting belongs in a separate performance pass.
chunkSizeWarningLimit: 1200
},
resolve: {
preserveSymlinks: true,
dedupe: ["react", "react-dom", "react-router-dom"],
alias: [
{ find: "@govoplan/core-webui/app", replacement: fileURLToPath(new URL("./src/app.ts", import.meta.url)) },
{ find: "@govoplan/core-webui", replacement: fileURLToPath(new URL("./src/index.ts", import.meta.url)) }
]
},
server: {
fs: {
allow: [
fileURLToPath(new URL('.', import.meta.url)),
fileURLToPath(new URL('../../govoplan-access/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-admin/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-calendar/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-dashboard/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-docs/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-files/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-idm/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-mail/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-organizations/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-campaign/webui', import.meta.url)),
fileURLToPath(new URL('../../govoplan-ops/webui', import.meta.url))
]
},
proxy: {
"/api": {
target: process.env.VITE_API_PROXY_TARGET || "http://127.0.0.1:8000",
changeOrigin: true
},
"/health": {
target: process.env.VITE_API_PROXY_TARGET || "http://127.0.0.1:8000",
changeOrigin: true
}
}
}
});