-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
106 lines (103 loc) · 3.2 KB
/
vite.config.ts
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
import react from "@vitejs/plugin-react";
import "dotenv/config";
import { exec } from "node:child_process";
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
// https://vitejs.dev/config/
export default defineConfig(async () => {
const apiUrl = process.env.API_URL;
if (!apiUrl) {
throw new Error("API_URL environment variable is not set");
}
// Validates URL
new URL(apiUrl);
const plausibleDomain = process.env.PLAUSIBLE_DOMAIN || null;
const plausibleScript = process.env.PLAUSIBLE_SCRIPT || "https://plausible.io/js/plausible.js";
const isBetaBuild = process.env.IS_BETA_BUILD === "true";
const commitShaDisplay = await new Promise((resolve, reject) => {
exec('git describe --always --abbrev=7 "--dirty=*" "--broken=!!" --exclude *', (err, stdout) => {
if (err) reject(err);
resolve(stdout.trim());
});
}).catch((err) => {
console.warn("Failed to get git information", err);
return null;
});
const commitSha = await new Promise((resolve, reject) => {
exec("git describe --always --abbrev=0 --exclude *", (err, stdout) => {
if (err) reject(err);
resolve(stdout.trim());
});
}).catch((err) => {
console.warn("Failed to get git information", err);
return null;
});
return {
define: {
__API_URL__: JSON.stringify(apiUrl),
__PLAUSIBLE_DOMAIN__: JSON.stringify(plausibleDomain),
__PLAUSIBLE_SCRIPT__: JSON.stringify(plausibleScript),
__IS_BETA_BUILD__: isBetaBuild,
__COMMIT_SHA_DISPLAY__: JSON.stringify(commitShaDisplay),
__COMMIT_SHA__: JSON.stringify(commitSha),
},
plugins: [
react(),
VitePWA({
registerType: "prompt",
devOptions: { enabled: true },
manifest: {
prefer_related_applications: true,
name: "Project Betoniera",
short_name: "Project Betoniera",
description: "Project Betoniera",
theme_color: "#0F6CBD",
start_url: "/?utm_source=pwa&utm_medium=start_url",
id: "/",
scope: "/",
protocol_handlers: [
{
protocol: "web+betoniera",
url: "/?protocol=%s&utm_source=pwa&utm_medium=protocol",
},
],
related_applications: [
{
id: "/",
platform: "webapp",
url: "http://betoniera.org/manifest.webmanifest",
},
],
display: "standalone",
icons: [
{
src: "icons/pwa-64x64.png",
sizes: "64x64",
type: "image/png",
},
{
src: "icons/pwa-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "icons/pwa-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "icons/maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
workbox: {
globPatterns: ["**/*.{js,css,html,svg,png}"],
},
}),
],
};
});