forked from VOICEVOX/voicevox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
99 lines (94 loc) · 2.91 KB
/
vite.config.ts
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
/// <reference types="vitest" />
import path from "path";
import { rmSync } from "fs";
import treeKill from "tree-kill";
import electron from "vite-plugin-electron";
import tsconfigPaths from "vite-tsconfig-paths";
import vue from "@vitejs/plugin-vue";
import checker from "vite-plugin-checker";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import { BuildOptions, defineConfig } from "vite";
import { quasar } from "@quasar/vite-plugin";
rmSync(path.resolve(__dirname, "dist"), { recursive: true, force: true });
const isElectron = process.env.VITE_IS_ELECTRON === "true";
export default defineConfig((options) => {
const shouldEmitSourcemap = ["development", "test"].includes(options.mode);
process.env.VITE_7Z_BIN_NAME =
(options.mode === "development"
? path.join(__dirname, "build", "vendored", "7z") + path.sep
: "") +
{
win32: "7za.exe",
linux: "7zzs",
darwin: "7zz",
}[process.platform];
const sourcemap: BuildOptions["sourcemap"] = shouldEmitSourcemap
? "inline"
: false;
return {
root: path.resolve(__dirname, "src"),
build: {
outDir: path.resolve(__dirname, "dist"),
chunkSizeWarningLimit: 10000,
sourcemap,
},
publicDir: path.resolve(__dirname, "public"),
css: {
preprocessorOptions: {
scss: {
includePaths: [path.resolve(__dirname, "node_modules")],
},
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "src/"),
},
},
test: {
include: [
path.resolve(__dirname, "tests/unit/**/*.spec.ts").replace(/\\/g, "/"),
],
environment: "happy-dom",
globals: true,
},
plugins: [
vue(),
quasar(),
nodePolyfills(),
options.mode !== "test" &&
checker({
overlay: false,
eslint: {
lintCommand: "eslint --ext .ts,.vue .",
},
typescript: true,
// FIXME: vue-tscの型エラーを解決したら有効化する
// vueTsc: true,
}),
isElectron &&
electron({
entry: ["./src/background.ts", "./src/electron/preload.ts"],
// ref: https://github.com/electron-vite/vite-plugin-electron/pull/122
onstart: ({ startup }) => {
// @ts-expect-error vite-electron-pluginはprocess.electronAppにelectronのプロセスを格納している。
// しかし、型定義はないので、ts-expect-errorで回避する。
const pid = process.electronApp?.pid;
if (pid) {
treeKill(pid);
}
if (options.mode !== "test") {
startup([".", "--no-sandbox"]);
}
},
vite: {
plugins: [tsconfigPaths({ root: __dirname })],
build: {
outDir: path.resolve(__dirname, "dist"),
sourcemap,
},
},
}),
],
};
});