File size: 3,264 Bytes
0d9f1af
 
 
b664dbe
0d9f1af
 
b664dbe
 
 
0d9f1af
 
 
 
 
b664dbe
 
 
 
0d9f1af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a60be0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d9f1af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a7b22d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d9f1af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { existsSync } from "fs";

export default defineConfig(({ mode }) => {
  // Check if we're in a workspace environment (has packages/web/src)
  const isWorkspace = existsSync(resolve(__dirname, "./packages/web/src"));

  const baseConfig = {
    plugins: [],
    resolve: {
      alias: {
        "@": resolve(__dirname, "./src"),
        // Only add workspace alias if in workspace environment
        ...(isWorkspace && {
          "@lerobot/web": resolve(__dirname, "./packages/web/src"),
        }),
      },
    },
  };

  if (mode === "demo") {
    // React demo mode - includes React, Tailwind, shadcn/ui
    return {
      ...baseConfig,
      plugins: [react()],
      css: {
        postcss: "./postcss.config.mjs",
      },
      build: {
        outDir: "dist/demo",
        rollupOptions: {
          input: {
            main: resolve(__dirname, "index.html"),
          },
        },
      },
    };
  }

  if (mode === "cyberpunk") {
    // Cyberpunk-themed robotics interface
    return {
      plugins: [react()],
      resolve: {
        alias: {
          "@": resolve(__dirname, "examples/cyberpunk-standalone/src"),
          // Only add workspace alias if in workspace environment
          ...(isWorkspace && {
            "@lerobot/web": resolve(__dirname, "./packages/web/src"),
          }),
        },
      },
      css: {
        postcss: "./postcss.config.mjs",
      },
      build: {
        outDir: resolve(__dirname, "dist/cyberpunk"),
        rollupOptions: {
          input: {
            main: resolve(
              __dirname,
              "examples/cyberpunk-standalone/index.html"
            ),
          },
        },
      },
      root: resolve(__dirname, "examples/cyberpunk-standalone"),
    };
  }

  if (mode === "vanilla") {
    // Vanilla mode - current implementation without React
    return {
      ...baseConfig,
      build: {
        outDir: "dist/vanilla",
        rollupOptions: {
          input: {
            main: resolve(__dirname, "vanilla.html"),
          },
        },
      },
    };
  }

  if (mode === "test") {
    // Test mode - sequential operations test
    return {
      ...baseConfig,
      server: {
        open: "/examples/test-sequential-operations.html",
      },
      build: {
        outDir: "dist/test",
        rollupOptions: {
          input: {
            main: resolve(
              __dirname,
              "examples/test-sequential-operations.html"
            ),
          },
        },
      },
    };
  }

  if (mode === "lib") {
    // Library mode - core library without any demo UI
    return {
      ...baseConfig,
      build: {
        lib: {
          entry: resolve(__dirname, "src/main.ts"),
          name: "LeRobot",
          fileName: "lerobot",
        },
        rollupOptions: {
          external: ["serialport", "react", "react-dom"],
          output: {
            globals: {
              serialport: "SerialPort",
              react: "React",
              "react-dom": "ReactDOM",
            },
          },
        },
      },
    };
  }

  // Default mode (fallback to demo)
  return defineConfig({ mode: "demo" });
});