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 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 => {