-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathvite.config.js
More file actions
92 lines (84 loc) · 2.55 KB
/
vite.config.js
File metadata and controls
92 lines (84 loc) · 2.55 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
import { defineConfig } from "vite";
import { sveltekit } from "@sveltejs/kit/vite";
import { execSync, spawnSync } from "child_process";
import { readFileSync, existsSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";
const host = process.env.TAURI_DEV_HOST;
const configDir = path.dirname(fileURLToPath(import.meta.url));
function getGitInfo() {
try {
return {
hash: execSync("git rev-parse HEAD").toString().trim(),
branch: execSync("git rev-parse --abbrev-ref HEAD").toString().trim(),
};
} catch {
return { hash: "unknown", branch: "unknown" };
}
}
function getVersion() {
try {
return JSON.parse(readFileSync("package.json", "utf8")).version;
} catch {
return "0.0.0";
}
}
function i18nKeysPlugin({ strict } = { strict: false }) {
return {
name: "omniget-i18n-keys",
buildStart() {
const script = path.join(configDir, "scripts", "generate-i18n-keys.js");
if (!existsSync(script)) {
return;
}
const args = strict ? [script, "--strict"] : [script];
const result = spawnSync(process.execPath, args, {
cwd: configDir,
stdio: "inherit",
});
if (result.status !== 0) {
throw new Error(
`generate-i18n-keys.js exited with code ${result.status}. ` +
`Fix locale keys or set OMNIGET_I18N_STRICT=0 to bypass.`,
);
}
},
};
}
export default defineConfig(async ({ command }) => {
const gitInfo = getGitInfo();
const isBuild = command === "build";
const strictI18n =
process.env.OMNIGET_I18N_STRICT === "1" ||
(isBuild && process.env.OMNIGET_I18N_STRICT !== "0");
return {
plugins: [i18nKeysPlugin({ strict: strictI18n }), sveltekit()],
define: {
__COMMIT_HASH__: JSON.stringify(gitInfo.hash),
__GIT_BRANCH__: JSON.stringify(gitInfo.branch),
__APP_VERSION__: JSON.stringify(getVersion()),
__BUILD_DATE__: JSON.stringify(new Date().toISOString().split("T")[0]),
},
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent Vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
// 3. tell Vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
},
},
};
});