I'd like to have multiple .env files with support to load them in order of precedence. For example, assume a project defines
.env
.env.local
If local exists, that file should be used. If not, it should load .env instead. This way, any CI/CD pipelines can use the .env file (included in source control) with templated values at build time, where as locally, I can simply redefine the file with the .local extension (excluded from source control) with the desired values.
I've looked into the suggestion on #434, but I'm not sure this is suitable to my situation as I can't rely on the NODE_ENV variable to determine whether we're doing a local build or serve versus a pipeline build as I have multiple environments being marked as development which are technically doing production builds but with different config, and so would like to avoid pipeline changes where possible.
Would the defaults feature of dotenv-webpack be suitable for this? For example, define .env.defaults as the tokenised values, and .env as containing the locally desired values (and therefore exclude .env from source control and include .env.defaults in source control?). Even if so, support for this dotenv feature would be great if possible.
Description
I'd like to have multiple
.env
files with support to load them in order of precedence. For example, assume a project defines.env
.env.local
If local exists, that file should be used. If not, it should load
.env
instead. This way, any CI/CD pipelines can use the.env
file (included in source control) with templated values at build time, where as locally, I can simply redefine the file with the.local
extension (excluded from source control) with the desired values.Example
In
dotenv
, you can pass anarray
topath
for such functionality (see: manage multiple environments) like so:It would be great if
dotenv-webpack
could support this syntax forpath
similarly, like so:Alternatives
I've looked into the suggestion on #434, but I'm not sure this is suitable to my situation as I can't rely on the
NODE_ENV
variable to determine whether we're doing a localbuild
orserve
versus a pipeline build as I have multiple environments being marked asdevelopment
which are technically doing production builds but with different config, and so would like to avoid pipeline changes where possible.Would the
defaults
feature ofdotenv-webpack
be suitable for this? For example, define.env.defaults
as the tokenised values, and.env
as containing the locally desired values (and therefore exclude.env
from source control and include.env.defaults
in source control?). Even if so, support for thisdotenv
feature would be great if possible.