-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.ts
More file actions
41 lines (39 loc) · 1.74 KB
/
env.ts
File metadata and controls
41 lines (39 loc) · 1.74 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
38
39
40
41
import {
defineConfig,
overrideDefineForWebAppServe,
Schema,
} from '@julr/vite-plugin-validate-env';
const webAppServeEnabled = process.env.WEB_APP_SERVE_ENABLED?.toLowerCase() === 'true';
if (webAppServeEnabled) {
// eslint-disable-next-line no-console
console.warn('Building application for web-app-serve');
}
const overrideDefine = webAppServeEnabled
? overrideDefineForWebAppServe
: undefined;
export default defineConfig({
overrideDefine,
validator: 'builtin',
schema: {
APP_TITLE: Schema.string(),
APP_ENVIRONMENT: (key: string, value: string) => {
// NOTE: APP_ENVIRONMENT_PLACEHOLDER is meant to be used with image builds
// The value will be later replaced with the actual value
const regex = /^production|staging|testing|alpha-\d+|development|APP_ENVIRONMENT_PLACEHOLDER$/;
const valid = !!value && (value.match(regex) !== null);
if (!valid) {
throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`);
}
if (value === 'APP_ENVIRONMENT_PLACEHOLDER') {
// eslint-disable-next-line no-console
console.warn(`Using ${value} for app environment. Make sure to not use this for builds without nginx-serve`);
}
return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development' | 'APP_ENVIRONMENT_PLACEHOLDER');
},
APP_GRAPHQL_CODEGEN_ENDPOINT: Schema.string(),
APP_GRAPHQL_DOMAIN: Schema.string(),
APP_UMAMI_SRC: Schema.string.optional(),
APP_UMAMI_ID: Schema.string.optional(),
APP_SENTRY_DSN: Schema.string.optional(),
},
});