|
1 | | -import { defineConfig, Schema } from '@julr/vite-plugin-validate-env'; |
| 1 | +import { defineConfig, Schema, overrideDefineForWebAppServe } from "@julr/vite-plugin-validate-env"; |
| 2 | + |
| 3 | +const webAppServeEnabled = process.env.WEB_APP_SERVE_ENABLED?.toLowerCase() === 'true'; |
| 4 | +if (webAppServeEnabled) { |
| 5 | + // eslint-disable-next-line no-console |
| 6 | + console.warn('Building application for web-app-serve'); |
| 7 | +} |
| 8 | +const overrideDefine = webAppServeEnabled |
| 9 | + ? overrideDefineForWebAppServe |
| 10 | + : undefined; |
2 | 11 |
|
3 | 12 | export default defineConfig({ |
4 | | - APP_TITLE: Schema.string(), |
5 | | - APP_ENVIRONMENT: (key, value) => { |
6 | | - // NOTE: APP_ENVIRONMENT_PLACEHOLDER is meant to be used with image builds |
7 | | - // The value will be later replaced with the actual value |
8 | | - const regex = /^production|staging|testing|alpha-\d+|development|APP_ENVIRONMENT_PLACEHOLDER$/; |
9 | | - const valid = !!value && (value.match(regex) !== null); |
10 | | - if (!valid) { |
11 | | - throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`); |
12 | | - } |
13 | | - if (value === 'APP_ENVIRONMENT_PLACEHOLDER') { |
14 | | - console.warn(`Using ${value} for app environment. Make sure to not use this for builds without nginx-serve`) |
15 | | - } |
16 | | - return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development' | 'APP_ENVIRONMENT_PLACEHOLDER'); |
| 13 | + overrideDefine, |
| 14 | + validator: 'builtin', |
| 15 | + schema: { |
| 16 | + // NOTE: These are the dynamic env variables |
| 17 | + APP_TITLE: Schema.string(), |
| 18 | + APP_ENVIRONMENT: (key, value) => { |
| 19 | + // NOTE: APP_ENVIRONMENT_PLACEHOLDER is meant to be used with image builds |
| 20 | + // The value will be later replaced with the actual value |
| 21 | + const regex = /^production|staging|testing|alpha-\d+|development|APP_ENVIRONMENT_PLACEHOLDER$/; |
| 22 | + const valid = !!value && (value.match(regex) !== null); |
| 23 | + if (!valid) { |
| 24 | + throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`); |
| 25 | + } |
| 26 | + if (value === 'APP_ENVIRONMENT_PLACEHOLDER') { |
| 27 | + console.warn(`Using ${value} for app environment. Make sure to not use this for builds without nginx-serve`) |
| 28 | + } |
| 29 | + return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development' | 'APP_ENVIRONMENT_PLACEHOLDER'); |
| 30 | + }, |
| 31 | + APP_GRAPHQL_CODEGEN_ENDPOINT: Schema.string(), |
| 32 | + APP_GRAPHQL_DOMAIN: Schema.string(), |
| 33 | + APP_UMAMI_SRC: Schema.string.optional(), |
| 34 | + APP_UMAMI_ID: Schema.string.optional(), |
| 35 | + APP_SENTRY_DSN: Schema.string.optional(), |
| 36 | + |
17 | 37 | }, |
18 | | - APP_GRAPHQL_CODEGEN_ENDPOINT: Schema.string(), |
19 | | - APP_GRAPHQL_DOMAIN: Schema.string(), |
20 | | - APP_UMAMI_SRC: Schema.string.optional(), |
21 | | - APP_UMAMI_ID: Schema.string.optional(), |
22 | | - APP_SENTRY_DSN: Schema.string.optional(), |
23 | 38 | }); |
0 commit comments