-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
vite.config.mts
102 lines (97 loc) · 3.64 KB
/
vite.config.mts
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
import react from "@vitejs/plugin-react";
import { join } from "path";
import electron from "vite-plugin-electron";
import renderer from "vite-plugin-electron-renderer";
import { defineConfig } from "vitest/config";
import pkg from "./package.json";
const rendererRoot = join(__dirname, "src", "renderer");
const rendererOutDir = join(__dirname, "dist-renderer");
const mainEntryPoint = join(__dirname, "src", "main", "index.ts");
const mainOutDir = join(__dirname, "dist-main");
const preloadEntryPoint = join(__dirname, "src", "preload", "index.ts");
const preloadOutDir = join(__dirname, "dist-preload");
export default defineConfig(({ command }) => {
const isServe = command === "serve";
const isBuild = command === "build";
const sourcemap = isServe || process.argv.includes("--sourcemap");
return {
root: rendererRoot,
resolve: {
alias: {
"@common": join(__dirname, "src", "common"),
"@Core": join(__dirname, "src", "renderer", "Core"),
},
},
build: {
outDir: rendererOutDir,
emptyOutDir: true,
chunkSizeWarningLimit: 1000,
},
plugins: [
react(),
electron([
{
entry: mainEntryPoint,
onstart(options) {
options.startup();
},
vite: {
resolve: {
alias: {
"@common": join(__dirname, "src", "common"),
"@Core": join(__dirname, "src", "main", "Core"),
},
},
build: {
sourcemap,
minify: isBuild,
outDir: mainOutDir,
emptyOutDir: true,
rollupOptions: {
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {}),
},
},
},
},
{
entry: preloadEntryPoint,
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload();
},
vite: {
resolve: {
alias: {
"@common": join(__dirname, "src", "common"),
},
},
build: {
sourcemap,
minify: isBuild,
outDir: preloadOutDir,
emptyOutDir: true,
rollupOptions: {
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {}),
},
},
},
},
]),
process.env.NODE_ENV === "test" ? null : renderer(),
],
server: (() => ({
host: "127.0.0.1",
port: 7777,
}))(),
clearScreen: false,
test: {
root: "src",
isolate: false, // This makes the tests run faster
coverage: {
include: ["**/*.ts"],
exclude: ["**/index.ts", "**/*.test.ts"],
},
},
};
});