Skip to content

Commit

Permalink
🔥 [#724] Drop support for CRA envvars
Browse files Browse the repository at this point in the history
These have been replaced with their VITE_* counterparts or are entirely
obsoleted now.
  • Loading branch information
sergei-maertens committed Jan 6, 2025
1 parent eee8f1d commit 4025947
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
7 changes: 0 additions & 7 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,3 @@ VITE_VERSION=latest
VITE_BASE_API_URL=http://localhost:8000/api/v2/
VITE_FORM_ID=93c09209-5fb9-4105-b6bb-9d9f0aa6782c
VITE_USE_HASH_ROUTING=false

# Legacy
DISABLE_ESLINT_PLUGIN=true
REACT_APP_VERSION=latest
REACT_APP_BASE_API_URL=http://localhost:8000/api/v2/
REACT_APP_FORM_ID=93c09209-5fb9-4105-b6bb-9d9f0aa6782c
REACT_APP_USE_HASH_ROUTING=false
2 changes: 0 additions & 2 deletions .env.production

This file was deleted.

31 changes: 7 additions & 24 deletions src/env.mjs
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
/**
* Handle the env in both (legacy) CRA and the new Vite-based setup.
* Abstract away reading from the env.
*
* CRA is `process.env` based, using NodeJS, while ViteJS used import.meta from the
* module system.
* Envvars tend to be tightly coupled around build tools. While we only support Vite
* at this moment, it might be useful to avoid leaking the build tool in source code
* directly in case another tool starts getting better supported in the future.
*/

let env;
let envVarPrefix = 'VITE';

let DEBUG = false;

// Support both CRA and Vite for the time being.
try {
// eslint-disable-next-line no-undef
env = process.env;
// it's legacy create-react-app
DEBUG = env.NODE_ENV === 'development';
envVarPrefix = 'REACT_APP';
} catch (error) {
if (error instanceof ReferenceError) {
// it's ViteJS, which doesn't know `process`
env = import.meta.env;
DEBUG = env.MODE === 'development';
} else {
throw error;
}
}
const env = import.meta.env;
const envVarPrefix = 'VITE';
const DEBUG = env.MODE === 'development';

const getEnv = name => {
const fullName = `${envVarPrefix}_${name}`;
Expand Down
6 changes: 3 additions & 3 deletions src/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ Alternatively (read: full stack developer) you can set up the
It is recommended to configure your local environment through `.env.local`, example content:

```
REACT_APP_BASE_API_URL=http://localhost:8000/api/v1/
REACT_APP_FORM_ID=dev
VITE_BASE_API_URL=http://localhost:8000/api/v1/
VITE_FORM_ID=dev
```

For `REACT_APP_FORM_ID`, use the slug or UUID of a form that you have
For `VITE_FORM_ID`, use the slug or UUID of a form that you have
[built](https://open-forms.readthedocs.io/en/stable/manual/forms/basics.html#nieuw-formulier-aanmaken)
in the backend environment.

Expand Down

0 comments on commit 4025947

Please sign in to comment.