From 3e2972275f26284083338e1c9e3b7a3c56f4d842 Mon Sep 17 00:00:00 2001 From: Ripal Nathuji Date: Fri, 13 Jan 2023 12:13:55 -0600 Subject: [PATCH] Update env usage for new conventions in Vite 4 There were a couple of improvements in the updated version of Vite around decoupling build modes and NODE_ENV: * https://github.com/vitejs/vite/pull/10996 * https://github.com/vitejs/vite/pull/11045 Accordingly, this change: * Consistently uses import.meta.env.MODE to set build mode specific values vs relying on the (previous) behavior around how import.meta.env.PROD was set. * Adds a development environment file so NODE_ENV is set to development for this builds. --- .env.development | 1 + src/lib/env.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .env.development diff --git a/.env.development b/.env.development new file mode 100644 index 00000000..c0d66521 --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +NODE_ENV=development diff --git a/src/lib/env.ts b/src/lib/env.ts index 95d11547..940bb949 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -1,10 +1,10 @@ export const ENV = { - OS_RAISE_CONTENT_URL_PREFIX: import.meta.env.PROD ? 'https://k12.openstax.org/contents/raise' : 'http://localhost:8800/contents', + OS_RAISE_CONTENT_URL_PREFIX: import.meta.env.MODE === 'production' ? 'https://k12.openstax.org/contents/raise' : 'http://localhost:8800/contents', OS_RAISE_EVENTSAPI_URL_MAP: {}, EVENT_FLUSH_PERIOD: 60000 } -if (import.meta.env.PROD) { +if (import.meta.env.MODE === 'production') { ENV.OS_RAISE_EVENTSAPI_URL_MAP = { 'raiselearning.org': 'https://events.raiselearning.org', 'staging.raiselearning.org': 'https://events.staging.raiselearning.org'