-
Notifications
You must be signed in to change notification settings - Fork 136
/
vite.config.mts
86 lines (81 loc) · 2.15 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
/// <reference types="vitest" />
import {type Plugin, defineConfig, createFilter} from "vite";
import vitePluginFaviconsInject from "vite-plugin-favicons-inject";
import inject from "@rollup/plugin-inject";
import peggy from "peggy";
import {readFileSync} from "fs";
import {resolve} from "path";
import {execSync} from "child_process";
const GIT_VERSION = JSON.stringify(
`${execSync("git log -1 --format=%cd --date=short", {
encoding: "utf-8"
}).trim()}/${execSync("git describe --always", {encoding: "utf-8"}).trim()}`
);
const dependencies = JSON.parse(
readFileSync("package.json", {encoding: "utf-8"})
)["dependencies"];
const APP_DEPENDENCIES = JSON.stringify(
Object.keys(dependencies)
.map((dependency) =>
JSON.parse(
readFileSync(`node_modules/${dependency}/package.json`, {
encoding: "utf8"
})
)
)
.map(
({name, version, license}) =>
`<a href="https://www.npmjs.com/package/${name}/v/${version}">${name}</a> ${version} (${license})`
)
.join(", ")
);
// https://vitejs.dev/config/
export default defineConfig(() => ({
base: "./",
optimizeDeps: {
exclude: ["leaflet"]
},
build: {
sourcemap: true,
rollupOptions: {
input: [
resolve(__dirname, "index.html"),
resolve(__dirname, "land.html"),
resolve(__dirname, "map.html")
]
}
},
define: {
APP_DEPENDENCIES,
GIT_VERSION
},
plugins: [
inject({
exclude: /(css|pegjs)$/,
$: "jquery",
jQuery: "jquery"
}),
peggyPlugin(),
vitePluginFaviconsInject("./turbo.svg")
],
// https://vitest.dev/config/
test: {
environment: "happy-dom",
include: ["tests/test*.ts"]
}
}));
function peggyPlugin(options: peggy.ParserBuildOptions = {}): Plugin {
return {
name: "peggy",
transform(grammar, id) {
const {include = ["*.pegjs", "**/*.pegjs"], exclude} = options;
const filter = createFilter(include, exclude);
if (!filter(id)) return null;
const code = peggy.generate(grammar, {output: "source", ...options});
return {
code: `export default ${code};`,
map: {mappings: ""}
};
}
};
}