Implement AXIS parity UI and execution baseline
This commit is contained in:
52
web/react/vite.config.ts
Normal file
52
web/react/vite.config.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { cpSync, createReadStream, existsSync, statSync } from "node:fs";
|
||||
import { extname, relative, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { defineConfig, type Plugin } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
const repoRoot = fileURLToPath(new URL("../../", import.meta.url));
|
||||
const sourceRoot = resolve(repoRoot, "linuxcnc");
|
||||
const contentTypes: Record<string, string> = {
|
||||
".ini": "text/plain; charset=utf-8", ".hal": "text/plain; charset=utf-8", ".inc": "text/plain; charset=utf-8", ".tbl": "text/plain; charset=utf-8", ".var": "text/plain; charset=utf-8", ".tcl": "text/plain; charset=utf-8", ".ngc": "text/plain; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8", ".gif": "image/gif", ".png": "image/png", ".svg": "image/svg+xml",
|
||||
};
|
||||
|
||||
function linuxcncAssets(): Plugin {
|
||||
return {
|
||||
name: "linuxcnc-exact-path-assets",
|
||||
configureServer(server) {
|
||||
server.middlewares.use((request, response, next) => {
|
||||
const requestPath = request.url?.split("?", 1)[0] ?? "";
|
||||
const mounts: Record<string, string> = { "/linuxcnc/": "linuxcnc", "/worker/": "web/worker", "/workspace/": "web/workspace", "/build-wasm/": "build-wasm" };
|
||||
const mount = Object.keys(mounts).find((prefix) => requestPath.startsWith(prefix));
|
||||
if (!mount) { next(); return; }
|
||||
const mountRoot = resolve(repoRoot, mounts[mount]);
|
||||
const relativePath = decodeURIComponent(requestPath.slice(mount.length));
|
||||
const target = resolve(mountRoot, relativePath);
|
||||
const safe = relative(mountRoot, target);
|
||||
if (safe.startsWith("..") || safe.includes("\\") || !existsSync(target) || !statSync(target).isFile()) { response.statusCode = 404; response.end(); return; }
|
||||
response.statusCode = 200;
|
||||
response.setHeader("Content-Type", contentTypes[extname(target).toLowerCase()] ?? "application/octet-stream");
|
||||
createReadStream(target).pipe(response);
|
||||
});
|
||||
},
|
||||
writeBundle(options) {
|
||||
const output = options.dir ? resolve(options.dir) : resolve(repoRoot, "web/react/dist");
|
||||
const copies = [
|
||||
["linuxcnc/configs/sim/axis", "linuxcnc/configs/sim/axis"],
|
||||
["linuxcnc/share/axis/images", "linuxcnc/share/axis/images"],
|
||||
["linuxcnc/lib/hallib", "linuxcnc/lib/hallib"],
|
||||
["linuxcnc/configs/sim/qtvcp_screens/qtaxis_lathe/qtaxis/images", "linuxcnc/configs/sim/qtvcp_screens/qtaxis_lathe/qtaxis/images"],
|
||||
];
|
||||
for (const [from, to] of copies) cpSync(resolve(repoRoot, from), resolve(output, to), { recursive: true, dereference: false });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [linuxcncAssets(), tailwindcss(), react()],
|
||||
base: "./",
|
||||
worker: { format: "iife" },
|
||||
server: { fs: { allow: ["../.."] } },
|
||||
build: { outDir: "dist", emptyOutDir: true },
|
||||
});
|
||||
Reference in New Issue
Block a user