Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
136 lines (125 loc) · 5.09 KB
/
Copy pathvite.config.ts
File metadata and controls
136 lines (125 loc) · 5.09 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/// <reference types="vitest" />
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import monacoEditorPluginPkg from "vite-plugin-monaco-editor";
const monacoEditorPlugin =
monacoEditorPluginPkg.default || monacoEditorPluginPkg;
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
plugins: [
react(),
monacoEditorPlugin({
languageWorkers: [
"editorWorkerService",
"typescript",
"json",
"css",
"html",
],
}),
],
build: {
target: "esnext",
rollupOptions: {
output: {
manualChunks(id) {
// Vite's internal dynamic-import preload helper is pulled in by
// every lazy route and every dynamic import() (monaco's own
// per-language loading included). Left unpinned, Rollup's
// automatic chunking parked it inside whichever manual vendor
// chunk happened to use it most, forcing every lazy route to load
// that entire vendor chunk just to reach this helper. Pin it to
// the always-loaded framework chunk instead.
if (id.includes("vite/preload-helper")) return "vendor-react";
if (!id.includes("node_modules")) return undefined;
// Pin the framework runtime to its own chunk first. Without this,
// forcing react-flow-renderer's modules into a separate chunk
// caused Rollup to duplicate React's own module into that chunk
// instead of sharing the single copy used by the rest of the app.
if (
id.includes("/node_modules/react/") ||
id.includes("/node_modules/react-dom/") ||
id.includes("/node_modules/scheduler/")
) {
return "vendor-react";
}
// Tiny stateless helper packages pulled in by several of the
// heavy libraries below (react-flow-renderer, 3d-force-graph).
// Pinning them here (rather than letting Rollup park them inside
// one specific vendor chunk) stops routes that only need one
// heavy library from having to fetch another's whole chunk just
// to reach a shared helper function.
if (id.includes("/@babel/runtime/") || id.includes("/tslib/")) {
return "vendor-react";
}
// Small d3 utility packages pulled in both by react-flow-renderer
// (via d3-zoom/d3-transition) and by 3d-force-graph (via
// d3-scale-chromatic/tween helpers). Pinning them stops the two
// heavy graph libraries' chunks from statically depending on
// one another.
if (
id.includes("/d3-color/") ||
id.includes("/d3-interpolate/") ||
id.includes("/d3-timer/")
) {
return "vendor-react";
}
// Monaco lazily splits its own per-language and language-service
// chunks (csharp, typescript, tsMode, etc.) via internal dynamic
// imports - leave those alone so they keep loading on demand.
if (
id.includes("/monaco-editor/esm/vs/basic-languages/") ||
id.includes("/monaco-editor/esm/vs/language/")
) {
return undefined;
}
if (
id.includes("/monaco-editor/") ||
id.includes("/monaco-editor-workers/") ||
id.includes("/vite-plugin-monaco-editor/")
) {
return "monaco-editor";
}
// Kept as separate chunks (rather than one shared "graph-libs"
// bundle) so a route using only one of these - e.g. BatchMultiCall
// with react-flow-renderer - never pulls in the other two.
if (id.includes("/3d-force-graph/")) return "vendor-3d-force-graph";
if (id.includes("/cytoscape/")) return "vendor-cytoscape";
if (id.includes("/react-flow-renderer/"))
return "vendor-react-flow-renderer";
if (id.includes("/@webcontainer/")) return "vendor-webcontainer";
if (id.includes("/jszip/")) return "vendor-jszip";
return undefined;
},
},
},
},
// Dev-only proxy so relative "/api" requests (src/api.ts) reach the
// indexer without needing VITE_API_URL set. Target is configurable via
// VITE_INDEXER_URL to match whatever indexer instance is running
// locally; nginx.conf covers the equivalent proxying in production.
server: {
proxy: { "/api": env.VITE_INDEXER_URL || "http://localhost:3001" },
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
test: {
environment: "jsdom",
globals: true,
setupFiles: ["./test/setup.ts"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
statements: 80,
branches: 80,
functions: 80,
lines: 80,
},
},
};
});