Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
131 lines (126 loc) · 3.91 KB
/
Copy pathvite.config.js
File metadata and controls
131 lines (126 loc) · 3.91 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { readFileSync } from "fs";
import { resolve } from "path";
import { defineConfig } from "vite";
import { checker } from "vite-plugin-checker";
import { VitePWA } from "vite-plugin-pwa";
import pkg from "./package.json" with { type: "json" };
import { resolveRelativeFixtureTimes } from "./scripts/fixture-times.mjs";
function devFixturesPlugin() {
const fixtureRoot = resolve(import.meta.dirname, "dev-fixtures");
const routes = {
"/config.json": {
filePath: resolve(fixtureRoot, "config.json"),
contentType: "application/json; charset=utf-8",
},
"/fixtures/meshviewer.json": {
filePath: resolve(fixtureRoot, "meshviewer.json"),
contentType: "application/json; charset=utf-8",
transform(body) {
return JSON.stringify(resolveRelativeFixtureTimes(JSON.parse(body)), null, 2);
},
},
"/grafana-node.json": {
filePath: resolve(fixtureRoot, "grafana-node.json"),
contentType: "application/json; charset=utf-8",
},
"/grafana-link.json": {
filePath: resolve(fixtureRoot, "grafana-link.json"),
contentType: "application/json; charset=utf-8",
},
"/grafana-global.json": {
filePath: resolve(fixtureRoot, "grafana-global.json"),
contentType: "application/json; charset=utf-8",
},
};
return {
name: "meshviewer-dev-fixtures",
configureServer(server) {
server.middlewares.use((req, res, next) => {
const route = req.url?.split("?")[0];
const fixture = routes[route];
if (!fixture) {
next();
return;
}
try {
const source = readFileSync(fixture.filePath, "utf8");
const body = fixture.transform ? fixture.transform(source) : source;
res.setHeader("Cache-Control", "no-store");
res.setHeader("Content-Type", fixture.contentType);
res.end(body);
} catch (error) {
res.statusCode = 500;
res.setHeader("Content-Type", "text/plain; charset=utf-8");
res.end(`Failed to load fixture ${fixture.filePath}: ${error.message}`);
}
});
},
};
}
export default defineConfig(({ command, mode }) => ({
base: "./",
resolve: {
alias: {
"@fonts": resolve(import.meta.dirname, "assets/fonts"),
"@icons": resolve(import.meta.dirname, "assets/icons/svg"),
},
},
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
},
build: {
outDir: "build",
sourcemap: true,
chunkSizeWarningLimit: 2000,
rollupOptions: {
input: {
embed: resolve(import.meta.dirname, "embed/index.html"),
index: resolve(import.meta.dirname, "index.html"),
},
},
},
plugins: [
command === "serve" && mode === "fixtures" ? devFixturesPlugin() : null,
VitePWA({
registerType: "autoUpdate",
workbox: {
globPatterns: ["**/*.{js,css,html,ico,png,svg,ttf,woff,woff2}"],
// Matched against pathname + search: keep the index.html fallback off
// real files, otherwise /sw.js is served as the app itself.
navigateFallbackDenylist: [/\.[a-z0-9]+(\?|$)/i],
cleanupOutdatedCaches: true,
},
manifest: {
name: "Meshviewer",
short_name: "Meshviewer",
description:
"Meshviewer is an online visualization app to represent nodes and links on a map for Freifunk open mesh network.",
theme_color: "#ffffff",
icons: [
{
src: "pwa-64x64.png",
sizes: "64x64",
type: "image/png",
},
{
src: "pwa-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "pwa-512x512.png",
sizes: "512x512",
type: "image/png",
},
],
},
devOptions: {
enabled: false,
},
}),
checker({
// Run TypeScript checks
typescript: true,
}),
].filter(Boolean),
}));