-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvite.config.ts
More file actions
71 lines (66 loc) · 2.83 KB
/
Copy pathvite.config.ts
File metadata and controls
71 lines (66 loc) · 2.83 KB
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
import { defineConfig } from "vite";
import type { Connect, Plugin } from "vite";
import react from "@vitejs/plugin-react";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { apiMiddleware } from "./server/http/vite-middleware";
const root = path.dirname(fileURLToPath(import.meta.url));
/**
* Runs the API inside the dev and preview servers so `npm run dev` is a single
* command. The routes come from server/http/routes.ts, the same table the
* production Express server reads.
*/
function localApiPlugin(): Plugin {
const attach = (middlewares: Connect.Server) => {
middlewares.use(apiMiddleware());
};
return {
name: "local-api-routes",
configureServer: (server) => attach(server.middlewares),
configurePreviewServer: (server) => attach(server.middlewares),
};
}
export default defineConfig({
server: { host: "0.0.0.0", port: 8001 },
preview: { host: "0.0.0.0", port: 8001 },
resolve: {
alias: {
"@contracts": path.resolve(root, "contracts"),
"@prompts": path.resolve(root, "resources/prompts"),
"@": path.resolve(root, "client"),
},
},
optimizeDeps: { entries: ["index.html"] },
build: {
sourcemap: "hidden",
rollupOptions: {
output: {
// Split by package. The object form of manualChunks makes each listed
// package a chunk entry, which let Vite's dynamic-import preload
// helper get hoisted into a vendor chunk and pulled into the initial
// load; returning undefined leaves placement to Rollup.
manualChunks(id: string) {
// Every lazy chunk needs this helper. Left to Rollup it landed in
// the PowerPoint chunk, which made the entry preload 800 kB.
if (id.includes("vite/preload-helper")) return "vendor-react";
if (!id.includes("node_modules")) return;
const match = /node_modules[\\/](?:(@[^\\/]+)[\\/])?([^\\/]+)/.exec(id);
const pkg = match ? `${match[1] ? `${match[1]}/` : ""}${match[2]}` : "";
if (pkg === "react" || pkg === "react-dom" || pkg === "scheduler") return "vendor-react";
if (pkg === "pptxgenjs" || pkg === "pdf-lib") return "vendor-office";
if (pkg === "jszip" || pkg === "pako") return "vendor-zip";
if (pkg === "mammoth") return "vendor-docs";
if (pkg === "react-markdown" || pkg === "remark-gfm" || pkg === "prism-react-renderer") {
return "vendor-markdown";
}
if (pkg === "react-drawio") return "vendor-drawio";
if (pkg === "ai" || pkg.startsWith("@ai-sdk/") || pkg === "openai") return "vendor-ai";
if (pkg === "lucide-react" || pkg === "motion" || pkg === "sonner") return "vendor-ui";
if (pkg.startsWith("@radix-ui/")) return "vendor-radix";
return;
},
},
},
},
plugins: [localApiPlugin(), react()],
});