From b95f3e4c68bd16532d1194ca7e65ca234188e38e Mon Sep 17 00:00:00 2001 From: James Zeng Date: Wed, 1 Mar 2023 23:44:45 +0000 Subject: [PATCH 1/2] Use REACT_APP_DOTENV_CONFIG_PATH if it is defined --- src/utils/Utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index d298989..e004d33 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -17,7 +17,8 @@ export function retrieveReactEnvCfg(): Record { export function retrieveDotEnvCfg(): Record { // eslint-disable-next-line @typescript-eslint/no-var-requires - const env = require('dotenv').config().parsed ?? {} + const path = process.env.REACT_APP_DOTENV_CONFIG_PATH ?? '.env'; + const env = require('dotenv').config({path: path}).parsed ?? {} const keys = Object.keys(env) const reactKeys = keys.filter(key => { From c3ceb8a19caed2202daa1e5f9837688cea6ed8fb Mon Sep 17 00:00:00 2001 From: James Zeng Date: Wed, 1 Mar 2023 23:50:00 +0000 Subject: [PATCH 2/2] update the readme to include REACT_APP_DOTENV_CONFIG_PATH environment varaible --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 53e5865..dc4dadc 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ set REACT_APP_COLOR=navy&& set REACT_APP_MAIN_TEXT=Navy Background&& npx react-i `.env` files are supported. `react-inject-env` will automatically detect environment variables in your `.env` file located in your root folder. +If you want to customize the `.env` file name, you can define the file name in environment variable `REACT_APP_DOTENV_CONFIG_PATH`. + Note: Environment variables passed in through the command line will take precedence over `.env` variables. ## Typescript