94 lines
3.3 KiB
TypeScript
94 lines
3.3 KiB
TypeScript
import { localDevStatusPlugin } from "./scripts/lib/local-dev-status.mjs";
|
|
import tailwindcss from "@tailwindcss/vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
import { precompressAssets } from "./scripts/lib/precompress-assets.mjs";
|
|
import path from "path";
|
|
import { defineConfig } from "vite";
|
|
import { frontendManualChunk } from "./scripts/lib/frontend-chunking.mjs";
|
|
import { viteProxyTargets } from "./scripts/lib/service-endpoints.mjs";
|
|
|
|
export default defineConfig(() => {
|
|
const proxyTargets = viteProxyTargets(process.env);
|
|
const captureWorkbenchMockVideo = process.env.CAPTURE_WORKBENCH_MOCK_VIDEO?.trim();
|
|
let resolvedOutDir: string | undefined;
|
|
|
|
return {
|
|
plugins: [
|
|
react(),
|
|
localDevStatusPlugin(proxyTargets.api),
|
|
tailwindcss(),
|
|
{
|
|
name: "capture-workbench-local-video",
|
|
apply: "serve",
|
|
configureServer(server) {
|
|
server.middlewares.use("/__capture-workbench-mock.mp4", (request, response, next) => {
|
|
if (!captureWorkbenchMockVideo || !existsSync(captureWorkbenchMockVideo)) {
|
|
next();
|
|
return;
|
|
}
|
|
const size = statSync(captureWorkbenchMockVideo).size;
|
|
const range = request.headers.range;
|
|
response.setHeader("Accept-Ranges", "bytes");
|
|
response.setHeader("Content-Type", "video/mp4");
|
|
if (!range) {
|
|
response.setHeader("Content-Length", size);
|
|
createReadStream(captureWorkbenchMockVideo).pipe(response);
|
|
return;
|
|
}
|
|
const match = /^bytes=(\d+)-(\d*)$/.exec(range);
|
|
if (!match) {
|
|
response.statusCode = 416;
|
|
response.end();
|
|
return;
|
|
}
|
|
const start = Number(match[1]);
|
|
const end = match[2] ? Math.min(Number(match[2]), size - 1) : size - 1;
|
|
response.statusCode = 206;
|
|
response.setHeader("Content-Range", `bytes ${start}-${end}/${size}`);
|
|
response.setHeader("Content-Length", end - start + 1);
|
|
createReadStream(captureWorkbenchMockVideo, { start, end }).pipe(response);
|
|
});
|
|
},
|
|
},
|
|
{
|
|
name: "precompress-static-assets",
|
|
apply: "build",
|
|
configResolved(config) {
|
|
resolvedOutDir = config.build.outDir;
|
|
},
|
|
closeBundle() {
|
|
// Read final files, including public/vendor and late import-analysis transforms.
|
|
precompressAssets(path.resolve(process.cwd(), resolvedOutDir ?? "dist"));
|
|
},
|
|
},
|
|
],
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: frontendManualChunk,
|
|
},
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
"@": path.resolve(__dirname, "."),
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
// Only scan the app entry: untracked copies under local-data/ ship their own
|
|
// index.html and node_modules, which would otherwise load a second React.
|
|
entries: ["index.html"],
|
|
},
|
|
server: {
|
|
// HMR is disabled in AI Studio via DISABLE_HMR env var.
|
|
// Do not modify: file watching is disabled to prevent flickering during agent edits.
|
|
hmr: process.env.DISABLE_HMR !== "true",
|
|
proxy: {
|
|
"/api": proxyTargets.api,
|
|
"/worker-api": proxyTargets.worker,
|
|
},
|
|
},
|
|
};
|
|
});
|