Just eval the file right in the beginning of each config.exs
file. It will load the env of the .env
files every time the project is compiled.
__ENV__.file()
|> Path.dirname()
|> Path.join("../../../config/dotenv.exs")
|> Path.expand()
|> Code.eval_file()
# config/config.exs
import Config
Code.eval_file("./config/dotenv.exs")
The dotenv will override the env vars in the following order (highest defined variable overrides lower):
Hierarchy Priority | Filename | Environment | Should I .gitignore it? |
Notes |
---|---|---|---|---|
1st (highest) | .env.$ENV.local |
dev/test/prod | Yes! | Local overrides of environment-specific settings. |
2nd | .env.$ENV |
dev/test/prod | No. | Overrides of environment-specific settings. |
3rd | .env.local |
All Environments | Yes! | Local overrides |
Last | .env |
All Environments | No. | The Original® |