forked from Azgaar/Fantasy-Map-Generator
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
37 lines (33 loc) · 1.42 KB
/
Copy pathvite.config.ts
File metadata and controls
37 lines (33 loc) · 1.42 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
import { fileURLToPath, URL } from "node:url";
/**
* The desktop app ships the same renderer, minus the parts that only make sense on the web:
* analytics (a program that phones home on launch is a different bargain than a web page),
* and the PWA plumbing, which `public/main.js` already skips under Electron
*/
const ANALYTICS_HOSTS = ["www.googletagmanager.com", "stats.barrulus.com"];
/** matched by host rather than by the exact tag, so attribute order and line breaks cannot smuggle one through */
const analyticsTag = (host: string) =>
new RegExp(`<script\\b[^>]*src="https://${host.replace(/\./g, "\\.")}[^>]*>\\s*</script>\\s*`, "g");
const stripWebOnlyTags = {
name: "strip-web-only-tags",
transformIndexHtml: (html: string) =>
ANALYTICS_HOSTS.reduce((out, host) => out.replace(analyticsTag(host), ""), html)
.replace(/<script>\s*window\.dataLayer[\s\S]*?<\/script>\s*/, "")
.replace(/<link rel="manifest"[^>]*>\s*/, "")
};
export default ({ mode }: { mode: string }) => ({
root: "./src",
base: mode === "electron" ? "./" : process.env.NETLIFY ? "/" : "/Fantasy-Map-Generator/",
plugins: mode === "electron" ? [stripWebOnlyTags] : [],
build: {
outDir: mode === "electron" ? "../dist-electron/renderer" : "../dist",
assetsDir: "./",
emptyOutDir: mode === "electron"
},
publicDir: "../public",
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url))
}
}
});