-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.mts
100 lines (94 loc) · 3.04 KB
/
vite.config.mts
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
import path from "node:path";
import { sentryVitePlugin } from "@sentry/vite-plugin";
import react from "@vitejs/plugin-react";
import { type PluginOption, defineConfig, loadEnv } from "vite";
const injectEnvIntoHtmlPlugin = (mode: string): PluginOption => {
const env = loadEnv(mode, process.cwd(), "");
return {
name: "inject-env-html",
transformIndexHtml(html: string) {
return html.replace("$__APP_VERSION__$", JSON.stringify(env.APP_VERSION ?? "unknown"));
},
};
};
// Dependencies that are set in their own chunk
const CHUNKS_MAPPING = {
react: ["react", "react-dom"],
reactrouter: ["react-router"],
reacthookform: ["react-hook-form", "@hookform/resolvers"],
zod: ["zod"],
maplibregl: ["maplibre-gl"],
i18next: ["i18next", "i18next-http-backend"],
oidc: ["oidc-client-ts"],
headlessui: ["@headlessui/react"],
styledicons: ["@styled-icons"],
turf: ["@turf"],
};
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const enableSentry = env.ENABLE_SENTRY?.toLowerCase() === "true";
return {
resolve: {
alias: {
"@ou-ca/api": path.resolve(__dirname, "./src/services/api/generated"),
"@components": path.resolve(__dirname, "./src/components"),
"@hooks": path.resolve(__dirname, "./src/hooks"),
"@layouts": path.resolve(__dirname, "./src/layouts"),
"@services": path.resolve(__dirname, "./src/services"),
"@typings": path.resolve(__dirname, "./src/@types"),
"@utils": path.resolve(__dirname, "./src/utils"),
},
},
build: {
sourcemap: enableSentry ? "hidden" : false,
rollupOptions: {
output: {
manualChunks: (id) => {
for (const [chunk, modules] of Object.entries(CHUNKS_MAPPING)) {
for (const module of modules) {
if (id.includes(`node_modules/${module}/`)) {
return chunk;
}
}
}
},
},
},
},
server: {
port: 3000,
open: true,
},
plugins: [
injectEnvIntoHtmlPlugin(mode),
react(),
sentryVitePlugin({
disable: !enableSentry,
url: env.SENTRY_URL,
org: env.SENTRY_ORG,
project: env.SENTRY_PROJECT,
authToken: env.SENTRY_AUTH_TOKEN,
release: {
name: env.APP_VERSION,
// Don't inject the release as it will be picked up from sentry init
inject: false,
// Disabled while testing GlitchTip as it does not seem to work properly
// Probably because of GlitchTip does not link commits to releases at all
// setCommits: {
// auto: true,
// },
// GlitchTip does not seem happy with the new source map format
uploadLegacySourcemaps: {
paths: ["**/assets/*"],
ext: ["js", "map"],
urlPrefix: "~/assets",
},
},
sourcemaps: {
filesToDeleteAfterUpload: "**/assets/*.js.map",
},
telemetry: false,
}),
],
};
});