File size: 1,202 Bytes
b2301b7
 
 
dd0e29e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2301b7
 
dd0e29e
b2301b7
 
 
 
 
 
 
 
 
 
 
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
import { resolve } from "node:path";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig, type Plugin } from "vite";

const appRoutes = new Set([
  "",
  "devices",
  "accelerators",
  "systems",
  "models",
  "compare",
  "bounds",
]);

function appHtmlFallback(): Plugin {
  return {
    name: "local-frontier-app-html-fallback",
    configureServer(server) {
      server.middlewares.use((request, _response, next) => {
        if (request.method !== "GET" && request.method !== "HEAD") {
          next();
          return;
        }

        const url = new URL(request.url ?? "/", "http://local-frontier.dev");
        const route =
          decodeURIComponent(url.pathname).replace(/^\/+/, "").split("/")[0] ??
          "";
        if (appRoutes.has(route)) {
          request.url = `/app.html${url.search}`;
        }
        next();
      });
    },
  };
}

export default defineConfig({
  plugins: [appHtmlFallback(), react(), tailwindcss()],
  resolve: {
    alias: {
      "@": resolve(import.meta.dirname, "src"),
    },
  },
  build: {
    rollupOptions: {
      input: resolve(import.meta.dirname, "app.html"),
    },
  },
});