-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
114 lines (112 loc) · 3.6 KB
/
Copy pathvite.config.ts
File metadata and controls
114 lines (112 loc) · 3.6 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
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
import { readFileSync } from "node:fs";
import { createRequire } from "node:module";
import { dirname, join } from "node:path";
import { fileURLToPath, URL } from "node:url";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vitest/config";
const pdfjsWasmDir = join(
dirname(createRequire(import.meta.url).resolve("pdfjs-dist/package.json")),
"wasm",
);
const PDFJS_WASM_FILES = [
"openjpeg.wasm",
"openjpeg_nowasm_fallback.js",
"qcms_bg.wasm",
] as const;
const PDFJS_WASM_ROUTE = "/pdfjs-wasm";
// https://vitejs.dev/config/
export default defineConfig({
// Load .env from the monorepo root (../../) so all apps share one env file.
envDir: fileURLToPath(new URL("../..", import.meta.url)),
plugins: [
react(),
// Plugin to ensure PDF.js worker is served with correct MIME type
{
name: "configure-response-headers",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url?.endsWith(".mjs")) {
res.setHeader("Content-Type", "application/javascript");
}
next();
});
},
},
// Serves pdfjs-dist wasm assets (OpenJPEG + QCMS) at /pdfjs-wasm/.
// pdfjs resolves these lazily via the `wasmUrl` getDocument option
// when decoding JPEG2000 images or wide-gamut color profiles.
{
name: "pdfjs-wasm-assets",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (!req.url?.startsWith(`${PDFJS_WASM_ROUTE}/`)) return next();
const name = req.url.slice(PDFJS_WASM_ROUTE.length + 1).split("?")[0];
if (!(PDFJS_WASM_FILES as readonly string[]).includes(name)) {
return next();
}
const data = readFileSync(join(pdfjsWasmDir, name));
res.setHeader(
"Content-Type",
name.endsWith(".wasm")
? "application/wasm"
: "application/javascript",
);
res.end(data);
});
},
generateBundle() {
for (const name of PDFJS_WASM_FILES) {
this.emitFile({
type: "asset",
fileName: `pdfjs-wasm/${name}`,
source: readFileSync(join(pdfjsWasmDir, name)),
});
}
},
},
],
optimizeDeps: {
include: ["@ai-di/graph-workflow"],
},
// Resolve needed to address plugin-react v5 fast refresh issue.
resolve: {
dedupe: ["react", "react-dom"],
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
// Bundle graph-workflow from source: dist is CommonJS and Rollup cannot
// resolve named exports (e.g. validateGraphConfig) from the compiled output.
"@ai-di/graph-workflow": fileURLToPath(
new URL(
"../../packages/graph-workflow/src/index.browser.ts",
import.meta.url,
),
),
// Explicit aliases so Vite/Vitest always resolves to the same React
// instance in all environments (prevents "Invalid hook call" in CI).
react: fileURLToPath(
new URL("../../node_modules/react", import.meta.url),
),
"react-dom": fileURLToPath(
new URL("../../node_modules/react-dom", import.meta.url),
),
},
},
server: {
port: 3000,
host: true,
proxy: {
// All backend routes (including /api/auth/*) live under the /api prefix,
// so a single rule suffices — no path rewrite needed.
"/api": {
target: "http://localhost:3002",
changeOrigin: true,
secure: false,
},
},
},
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./src/test/setup.ts"],
},
});