-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
158 lines (144 loc) · 4.1 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* vite.config.ts */
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig, loadEnv, type UserConfig } from "vite";
import path from "path";
import { envSchema } from "./src/env/schema";
export default defineConfig(({ mode }): UserConfig => {
// Add signal handling
process.on('SIGINT', () => {
console.log('\nGracefully shutting down from SIGINT (Ctrl+C)');
process.exit(0);
});
try {
const env = loadEnv(mode, process.cwd(), "");
if (!env) {
throw new Error("Failed to load environment variables");
}
// Create public env vars object with error handling
const publicEnvVars = Object.fromEntries(
Object.entries(env)
.filter(([key]) => key.startsWith("PUBLIC_"))
.map(([key, value]) => {
if (!value) {
console.warn(`Warning: ${key} has no value`);
return [`import.meta.env.${key}`, '""']; // provide empty string as fallback
}
return [`import.meta.env.${key}`, JSON.stringify(value)]
})
);
const enableOpenTelemetry = env.ENABLE_OPENTELEMETRY === "true";
const isDevelopment = mode === "development";
const PROD_ORIGIN = "https://shared-services.eu.pvh.cloud";
const CDN_ORIGIN = "https://d2bgp0ri487o97.cloudfront.net";
const ALLOWED_ORIGINS = [
"https://capella-document-search.prd.shared-services.eu.pvh.cloud",
"https://capellaql.prd.shared-services.eu.pvh.cloud",
"https://shared-services.eu.pvh.cloud",
CDN_ORIGIN
];
const config: UserConfig = {
plugins: [sveltekit()],
envPrefix: ["PUBLIC_"],
server: {
fs: {
allow: ['.', 'static'],
strict: false,
},
port: parseInt(env.PORT || "5173"),
host: true,
cors: {
origin: '*',
methods: ['POST', 'OPTIONS'],
allowedHeaders: [
'Content-Type',
'Authorization',
'Content-Encoding',
'X-Openreplay-Batch'
],
credentials: false
},
hmr: {
timeout: 5000
},
proxy: {
'/openreplay': {
target: env.PUBLIC_OPENREPLAY_INGEST_POINT,
changeOrigin: true,
secure: true,
headers: {
traceparent: undefined,
tracestate: undefined
},
configure: (proxy, _options) => {
proxy.on('proxyReq', (proxyReq) => {
proxyReq.removeHeader('traceparent');
proxyReq.removeHeader('tracestate');
});
}
}
}
},
ssr: {
noExternal: ["@apollo/client", "@openreplay/tracker"],
external: ['bun:sqlite']
},
build: {
rollupOptions: {
external: [
'bun:sqlite',
...(enableOpenTelemetry
? [
"winston",
"winston-daily-rotate-file",
"@elastic/ecs-winston-format",
"@opentelemetry/winston-transport",
]
: [])
]
},
target: "esnext",
sourcemap: false,
},
optimizeDeps: {
exclude: enableOpenTelemetry ? ["src/utils/serverLogger"] : [],
include: [
'svelte',
'svelte/internal',
'svelte/store',
'svelte/easing',
'bits-ui',
'tailwind-merge'
],
},
define: {
...publicEnvVars,
},
esbuild: {
target: "esnext",
},
css: {
postcss: true,
},
};
if (!config.plugins || !config.server || !config.build) {
throw new Error("Invalid configuration object");
}
return config;
} catch (error) {
console.error("Vite configuration error:", error);
if (mode === "development") {
console.log("Using fallback development configuration");
return {
plugins: [sveltekit()],
server: {
port: 5173,
host: true,
hmr: {
timeout: 5000
}
},
};
}
throw error;
}
});