-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathvite.config.ts
More file actions
81 lines (77 loc) · 2.06 KB
/
vite.config.ts
File metadata and controls
81 lines (77 loc) · 2.06 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
import path from "path"
import react from "@vitejs/plugin-react"
import { defineConfig, type UserConfig } from "vite"
export default defineConfig(({ mode }) => {
if (mode === "main") {
return defineMainConfig()
}
if (mode === "renderer") {
return defineRendererConfig()
}
throw new Error(`Unsupported Vite config mode: ${mode}`)
})
function defineMainConfig(): UserConfig {
return {
root: path.resolve(__dirname, "./src/main"),
build: {
target: "esnext",
outDir: path.resolve(__dirname, "./out/main"),
emptyOutDir: true,
sourcemap: true,
lib: {
entry: path.resolve(__dirname, "./src/main/index.ts"),
formats: ["es"],
fileName: () => "index.js",
},
rollupOptions: {
external: [
"mobrowser",
// Externalize all Node.js built-in modules
/^node:.*/,
],
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src/main"),
},
},
server: {
forwardConsole: {
unhandledErrors: true,
logLevels: ['warn', 'error'],
},
},
}
}
function defineRendererConfig(): UserConfig {
return {
root: path.resolve(__dirname, "./src/renderer"),
plugins: [react()],
build: {
outDir: path.resolve(__dirname, "./out/renderer"),
emptyOutDir: true,
sourcemap: true,
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src/renderer"),
},
},
// web-txt2img and onnxruntime-web both use dynamic imports and worker
// URLs that Vite's dep pre-bundler cannot resolve statically. Excluding
// them keeps the packages as plain ES module imports at runtime.
optimizeDeps: {
exclude: ["web-txt2img", "onnxruntime-web", "@xenova/transformers"],
},
// Copy the onnxruntime-web WASM binaries into the build output so the
// runtime can fetch them from the same origin.
assetsInclude: ["**/*.wasm"],
server: {
forwardConsole: {
unhandledErrors: true,
logLevels: ['warn', 'error'],
},
},
}
}