-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathvite.config.ts
More file actions
125 lines (121 loc) · 3.7 KB
/
Copy pathvite.config.ts
File metadata and controls
125 lines (121 loc) · 3.7 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
import { defineConfig } from "vite";
import babel from "@rolldown/plugin-babel";
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
import viteProtobufPlugin from "./frontend/vite/vite-plugin-protobuf";
import replaceSvgColorWithCurrentColor from "./frontend/vite/vite-plugin-replace-svg-color";
import path from "node:path";
const alias = {
"@images": path.resolve(__dirname, "frontend/assets/images"),
"@wasm": path.resolve(__dirname, "frontend/assets/wasm"),
};
// https://vite.dev/config/
export const viteConfig = {
resolve: { alias, tsconfigPaths: true },
plugins: [
react(),
babel({
presets: [reactCompilerPreset()],
}),
svgr({
svgrOptions: {
plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
icon: true,
jsx: {
babelConfig: {
plugins: [[replaceSvgColorWithCurrentColor, { patchStroke: true, patchFill: true }]],
},
},
svgoConfig: {
plugins: [
{ name: "convertStyleToAttrs" }, // converts <SVG style="..."> to individual attrs
{
name: "preset-default",
},
],
},
},
}),
viteProtobufPlugin({
protoDir: "webknossos-datastore/proto",
}),
],
devtools: {
enabled: false,
},
optimizeDeps: {
exclude: ["three-mesh-bvh"],
},
build: {
outDir: "public", // note: /public is handled by the backend/Play framework for asset delivery
emptyOutDir: true,
sourcemap: true,
},
worker: {
format: "es" as const,
},
server: {
port: 9000,
cors: true,
// https: {
// // Enable HTTPS with self-signed certificates for testing passkeys etc
// // Make sure you've generated SSL certificates using the ./tools/gen-ssl-dev-certs.sh script
// key: fs.readFileSync("./target/dev.key.pem"),
// cert: fs.readFileSync("./target/dev.cert.pem"),
// },
proxy: {
// Proxy to SAM service
"^/dist/": {
target: "http://localhost:8080",
changeOrigin: true,
},
// Proxy to Tracingstore / Datastore
"^/(api|data(?!set)|tracings)": {
target: "http://localhost:9001",
changeOrigin: true,
},
},
hmr: false, // disable Hot Module Replacement for now
watch: {
ignored: [
"**/node_modules/**",
...[
"dist",
"app",
"webknossos-tracingstore",
"webknossos-datastore",
"util",
"webknossos-jni",
"conf",
"project",
"docs",
"fossildb",
"target",
"schema",
"tools",
"binaryData",
"coverage",
"public",
"public-test",
"unreleased_changes",
].map((dir) => path.resolve(__dirname, dir)),
],
},
},
define: {
// Vite does not automatically provide a `process` polyfill in the
// browser. a) the frontend code still contains a few legacy
// `process.env.*` checks and b) third‑party libraries might reference
// `process.env.NODE_ENV`. Without the mapping the dev server emits
// `process.env` literally which crashes because `process` is undefined
// in the browser. We only need a *compile‑time* replacement; the real
// object is never used at runtime.
global: "globalThis",
"process.env": {},
// we keep NODE_ENV for compatibility with existing checks in the repo
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
// the only custom value that is currently used in the client is IS_TESTING
"process.env.IS_TESTING": JSON.stringify(process.env.IS_TESTING ?? ""),
},
};
export default defineConfig(viteConfig);