-
-
Notifications
You must be signed in to change notification settings - Fork 209
/
vite.config.ts
131 lines (124 loc) · 4.27 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
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 macrosPlugin from "@insertish/vite-plugin-babel-macros";
import replace from "@rollup/plugin-replace";
import legacy from "@vitejs/plugin-legacy";
import { readFileSync } from "fs";
import { resolve } from "path";
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
import preact from "@preact/preset-vite";
function getGitRevision() {
try {
const rev = readFileSync(".git/HEAD").toString().trim();
if (rev.indexOf(":") === -1) {
return rev;
}
return readFileSync(`.git/${rev.substring(5)}`)
.toString()
.trim();
} catch (err) {
console.error("Failed to get Git revision.");
return "?";
}
}
function getGitBranch() {
try {
const rev = readFileSync(".git/HEAD").toString().trim();
if (rev.indexOf(":") === -1) {
return "DETACHED";
}
return rev.split("/").pop();
} catch (err) {
console.error("Failed to get Git branch.");
return "?";
}
}
function getVersion() {
return JSON.parse(readFileSync("package.json").toString()).version;
}
export default defineConfig({
plugins: [
preact(),
macrosPlugin(),
legacy({
targets: ["defaults", "not IE 11"],
}),
VitePWA({
srcDir: "src",
filename: "sw.ts",
strategies: "injectManifest",
manifest: {
name: "Revolt",
short_name: "Revolt",
description: "User-first, privacy-focused chat platform.",
categories: ["communication", "chat", "messaging"],
start_url: "/",
orientation: "portrait",
/*display_override: ["window-controls-overlay"],*/
display: "standalone",
background_color: "#101823",
theme_color: "#101823",
icons: [
{
src: `/assets/icons/android-chrome-192x192.png`,
type: "image/png",
sizes: "192x192",
},
{
src: `/assets/icons/android-chrome-512x512.png`,
type: "image/png",
sizes: "512x512",
},
{
src: `/assets/icons/monochrome.svg`,
type: "image/svg+xml",
sizes: "48x48 72x72 96x96 128x128 256x256",
purpose: "monochrome",
},
{
src: `/assets/icons/masking-512x512.png`,
type: "image/png",
sizes: "512x512",
purpose: "maskable",
},
],
//TODO: add shortcuts relating to your last opened direct messages
/*shortcuts: [
{
"name": "Open Play Later",
"short_name": "Play Later",
"description": "View the list of podcasts you saved for later",
"url": "/play-later?utm_source=homescreen",
"icons": [{ "src": "/icons/play-later.png", "sizes": "192x192" }]
},
{
"name": "View Subscriptions",
"short_name": "Subscriptions",
"description": "View the list of podcasts you listen to",
"url": "/subscriptions?utm_source=homescreen",
"icons": [{ "src": "/icons/subscriptions.png", "sizes": "192x192" }]
}
]*/
},
}),
replace({
__GIT_REVISION__: getGitRevision(),
__GIT_BRANCH__: getGitBranch(),
__APP_VERSION__: getVersion(),
preventAssignment: true,
}) as any,
],
build: {
sourcemap: true,
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
},
},
},
optimizeDeps: {
exclude: ["revolt.js", "preact-context-menu", "@revoltchat/ui"],
},
resolve: {
preserveSymlinks: true,
},
});