Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
105 lines (102 loc) · 3.58 KB
/
Copy pathvite.config.js
File metadata and controls
105 lines (102 loc) · 3.58 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
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import basicSsl from "@vitejs/plugin-basic-ssl";
import { VitePWA } from "vite-plugin-pwa";
import { execSync } from "child_process";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const isGitHubPages = process.env.GITHUB_PAGES === "true";
// Pages serves the site at /<repo-name>/ — case-sensitive. Derive it from CI
// so a repo rename can't silently break asset paths again.
const pagesBase = `/${(process.env.GITHUB_REPOSITORY ?? "x/FlightTrace").split("/")[1]}/`;
// Use the nearest git tag as the version. Falls back to package.json so dev
// builds without a tag still show something sensible.
function appVersion() {
try {
const tag = execSync("git describe --tags --abbrev=0", { encoding: "utf8", stdio: ["pipe","pipe","pipe"] }).trim();
return tag.startsWith("v") ? tag.slice(1) : tag;
} catch {
return require("./package.json").version;
}
}
const APP_VERSION = appVersion();
export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(APP_VERSION),
},
// GitHub Pages needs an absolute base (/<repo>/) for correct PWA scope.
// Electron needs "./" because it loads via file://.
base: isGitHubPages ? pagesBase : "./",
plugins: [
vue(),
basicSsl(),
VitePWA({
registerType: "autoUpdate",
injectRegister: false,
includeAssets: ["icon.svg"],
manifest: {
name: "FlightTrace",
short_name: "FlightTrace",
description:
"Drone telemetry viewer with CRSF, MAVLink, and LTM support over USB, BLE, and WiFi",
theme_color: "#050709",
background_color: "#050709",
display: "standalone",
orientation: "any",
start_url: isGitHubPages ? pagesBase : ".",
scope: isGitHubPages ? pagesBase : ".",
icons: [
{ src: "icon.svg", sizes: "any", type: "image/svg+xml", purpose: "any" },
{ src: "icon.svg", sizes: "any", type: "image/svg+xml", purpose: "maskable" },
],
},
workbox: {
globPatterns: ["**/*.{js,css,html,svg,ico,png,woff,woff2}"],
navigateFallback: "index.html",
// Map tiles + Google Fonts cached for offline use
runtimeCaching: [
{
urlPattern: ({ url }) => url.hostname === "tile.openstreetmap.org",
handler: "CacheFirst",
options: {
cacheName: "osm-tiles",
expiration: { maxEntries: 500, maxAgeSeconds: 60 * 60 * 24 * 30 },
cacheableResponse: { statuses: [0, 200] },
},
},
{
urlPattern: ({ url }) => url.hostname === "server.arcgisonline.com",
handler: "CacheFirst",
options: {
cacheName: "esri-tiles",
expiration: { maxEntries: 500, maxAgeSeconds: 60 * 60 * 24 * 30 },
cacheableResponse: { statuses: [0, 200] },
},
},
{
urlPattern: /^https:\/\/fonts\.(googleapis|gstatic)\.com\/.*/,
handler: "CacheFirst",
options: {
cacheName: "google-fonts",
expiration: { maxEntries: 50, maxAgeSeconds: 60 * 60 * 24 * 365 },
cacheableResponse: { statuses: [0, 200] },
},
},
],
},
devOptions: { enabled: false },
}),
],
server: {
port: 5173,
host: true,
https: true,
proxy: {
"/ws-bridge": {
target: "ws://localhost:14555",
ws: true,
rewrite: (path) => path.replace(/^\/ws-bridge/, ""),
},
},
},
});