-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
96 lines (88 loc) · 2.86 KB
/
vite.config.ts
File metadata and controls
96 lines (88 loc) · 2.86 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
/*
* Kaede, a Minecraft Launcher
* Copyright (C) 2026 windstone <notwindstone@gmail.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import path from "node:path";
import vue from "@vitejs/plugin-vue";
import unocss from "unocss/vite";
import eslint from "vite-plugin-eslint2";
// 'vitest/config' extends 'vite' config
import { defineConfig } from "vitest/config";
import kaedeExtraConfiguration from "./kaede-extra.json";
function handleSourceFileNames(): {
"name" : string;
"enforce" : "pre";
"transform": (source: string, id: string) => string;
} {
return {
"name" : "handle-source-file-names",
// Ensure that the sources we get are untouched by 'esbuild' and others
"enforce" : "pre",
"transform": (source: string, id: string): string => {
/*
* Replacing is not an option since 'process.cwd'
* returns 'letter:\path\...' when 'id' is 'letter:/path/...'
*/
const relativePath: string = id.slice(process.cwd().length);
// Avoid having 'const "/src/declarations.ts:90": string;' in the 'declarations.ts'
if (relativePath === "/src/declarations.ts") {
return source;
}
return source
.split("\n")
.map((line, index) => {
const lineNumber: number = index + 1;
return line.replaceAll(
"__PRE_BUNDLED_FILENAME__",
`"${relativePath}:${lineNumber}"`,
);
})
.join("\n");
},
};
}
export default defineConfig({
// Use '/kaede' base path for GitHub Pages
"base" : kaedeExtraConfiguration.useKaedeBase ? "/kaede" : undefined,
// Better support for Tauri CLI output
"clearScreen": false,
// Enable environment variables
"envPrefix" : ["VITE_", "TAURI_"],
"server" : {
// Tauri requires a consistent port
"strictPort": true,
},
// Handle '@/...' imports
"resolve": {
"alias": {
"@": path.resolve(__dirname, "./src"),
},
},
// Tests-related code
"test": {
"setupFiles": "vitest.setup.ts",
},
"plugins": [
// Replace all '__PRE_BUNDLED_FILENAME__,' variables at build time
handleSourceFileNames(),
// Handle a Vue framework
vue(),
// Handle a UnoCSS package
unocss(),
// Handle an ESLint package
eslint(),
],
});