I have multiple projects within a single repo and I would like to have single .env file in the very root. My other projects use dotenv npm package with path setting. Is there any option to support such approach for create-react-app project?
Hi @dhilt
good question, there was a similar issue raised about this in 2017 and I'm not sure whether any support for this has been planned since then: https://github.com/facebook/create-react-app/issues/1697
However, you could eject and configure the path like you mentioned:
require('dotenv').config({ path: '/full/custom/path/to/your/env/vars' })
If you don't want to eject, you could always create a little Bash script that loads in your central .env file and exports all environment variables into your shell before starting your React application. Or even easier, use dotenv-cli to do it for you:
"scripts": {
+ "build": "dotenv -e ../.env react-scripts build",
- "build": "react-scripts build",
}
Hope this helps :)
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.
Most helpful comment
Hi @dhilt
good question, there was a similar issue raised about this in 2017 and I'm not sure whether any support for this has been planned since then: https://github.com/facebook/create-react-app/issues/1697
However, you could eject and configure the path like you mentioned:
If you don't want to eject, you could always create a little Bash script that loads in your central
.envfile andexportsall environment variables into your shell before starting your React application. Or even easier, use dotenv-cli to do it for you:Hope this helps :)