mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
|
import { defineConfig } from "vitest/config";
|
|
import react from "@vitejs/plugin-react";
|
|
import tailwindcss from "@tailwindcss/vite";
|
|
import type { ViteDevServer, PreviewServer } from "vite";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
function userManagementSpaFallback() {
|
|
const rewrite = (req: IncomingMessage) => {
|
|
const url = req.url ?? '';
|
|
if (!url.startsWith('/_um/') && url !== '/_um') return;
|
|
if (/\.[a-zA-Z0-9]+$/.test(url.split('?')[0])) return;
|
|
req.url = '/_um/index.html';
|
|
};
|
|
return {
|
|
name: 'user-management-spa-fallback',
|
|
configureServer(s: ViteDevServer) {
|
|
s.middlewares.use((req: IncomingMessage, _r: ServerResponse, next: () => void) => {
|
|
rewrite(req);
|
|
next();
|
|
});
|
|
|
|
},
|
|
configurePreviewServer(s: PreviewServer) {
|
|
s.middlewares.use((req: IncomingMessage, _r: ServerResponse, next: () => void) => {
|
|
rewrite(req);
|
|
next();
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [userManagementSpaFallback(), react(), tailwindcss()],
|
|
resolve: {
|
|
alias: {
|
|
"@": path.resolve(__dirname, "./src"),
|
|
// Resolve from TS source so Vite gets ESM named exports (dist is CommonJS).
|
|
"@edr/types": path.resolve(__dirname, "../../../packages/types/src/index.ts"),
|
|
},
|
|
// Force a single copy of these singletons so MantineProvider context is
|
|
// shared between the backoffice app and @edr/ui-common (which ships its
|
|
// own node_modules copy). Without this, two separate @mantine/core
|
|
// instances are bundled and the context lookup fails at runtime.
|
|
dedupe: ["react", "react-dom", "@mantine/core", "@mantine/hooks"],
|
|
},
|
|
server: {
|
|
port: 5183,
|
|
host: "0.0.0.0",
|
|
},
|
|
test: {
|
|
environment: "node",
|
|
},
|
|
});
|