File size: 1,480 Bytes
092334a
 
 
 
 
 
 
 
c14ceee
092334a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { defineConfig } from "vite";
import type { Plugin } from "vite";
import react from "@vitejs/plugin-react";
import { viteSingleFile } from "vite-plugin-singlefile";

// ---------------------------------------------------------------------------
// EMBED build — inline EVERYTHING (JS + CSS) into ONE self-contained index.html
// so the grid can be hosted inside another app with no server and no side assets.
// Output: aios-web/web/dist-embed/index.html  (consumed by platform/aios_grid.py).
// The standalone build (vite.config.ts -> dist/) is unchanged and keeps the /api
// fetch path; this config only changes packaging, never the app code.
//   npm run build:embed
// ---------------------------------------------------------------------------

// Strip the /favicon.svg <link>: it is an EXTERNAL asset ref that singlefile does
// not inline, and it would 404 inside the embed iframe — removing it keeps the
// built file genuinely self-contained (no external refs at all).
function stripFaviconLink(): Plugin {
  return {
    name: "aios-strip-favicon",
    transformIndexHtml(html: string): string {
      return html.replace(/\s*<link\b[^>]*rel=["']icon["'][^>]*>/i, "");
    },
  };
}

// https://vite.dev/config/
export default defineConfig({
  plugins: [react(), stripFaviconLink(), viteSingleFile()],
  base: "./",
  build: {
    outDir: "dist-embed",
    // keep the standalone dist/ intact — never emptied by this build
    emptyOutDir: true,
  },
});