-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
64 lines (61 loc) · 1.72 KB
/
vite.config.mjs
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
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
const viteConfig = ({ mode }) => {
const isGhPagesBuild =
loadEnv(mode, process.cwd()).VITE_GH_PAGES_BUILD === "true";
return defineConfig({
server: {
proxy: {
"/api/v1": {
target: "http://localhost:8080/api/v1",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api\/v1/, ""),
},
"/auth": {
target: "http://localhost:8080/auth",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/auth/, ""),
},
},
},
base: isGhPagesBuild ? "/frontend/" : "/",
build: {
// https://stackoverflow.com/questions/76694615/module-level-directives-cause-errors-when-bundled-use-client-was-ignored-caus
rollupOptions: {
onwarn(warning, warn) {
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
return;
}
warn(warning);
},
},
},
plugins: [
react(),
{
name: "add-analytics",
apply: "build",
transformIndexHtml(html) {
if (isGhPagesBuild) {
return html.replace(
/<script analytics>(.*?)<\/script>/,
`<script defer src="https://us.umami.is/script.js" data-website-id="b636e4e9-a210-4ef5-a7e9-192e04b798c5"></script>`,
);
} else {
return html.replace(
/<script analytics>(.*?)<\/title>/,
"<!-- analytics not enabled -->",
);
}
},
},
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});
};
export default viteConfig;