generated from Simon-Laux/webxdc-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
64 lines (59 loc) · 1.36 KB
/
vite.config.js
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
import { defineConfig } from "vite";
import zipPack from "vite-plugin-zip-pack";
import { readFileSync } from "node:fs";
import * as toml from "toml";
const manifest = toml.parse(readFileSync("./public/manifest.toml", "utf-8"));
let name = manifest.name || "app";
let version = manifest.version ? "_" + manifest.version : "";
function eruda(debug = undefined) {
const erudaSrc = readFileSync("./node_modules/eruda/eruda.js", "utf-8");
return {
name: "vite-plugin-eruda",
apply: "build",
transformIndexHtml(html) {
const tags = [
{
tag: "script",
children: erudaSrc,
injectTo: "head",
},
{
tag: "script",
children: "eruda.init();",
injectTo: "head",
},
];
if (debug === true) {
return {
html,
tags,
};
} else if (debug === false) {
return html;
}
// @ts-ignore
if (process.env.NODE_ENV !== "production") {
return {
html,
tags,
};
} else {
return html;
}
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
zipPack({
outDir: "dist-xdc",
outFileName: name + version + ".xdc",
}),
eruda(),
],
// https://github.com/vitest-dev/vitest
test: {
environment: "jsdom",
},
});