You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently refactored my config logic to use the following code:
/** Get the named environment variable or return the provided default */constgetEnv=(name,backup)=>process.env[name]||backup;/** Ensure the environment variable is defined and return its value, or throw if it is undefined * * The environment variable is allowed to be empty (or null), as long as it is defined. */constgetAndEnsurePresentEnv=(name)=>{if(process.env[name]===undefined){thrownewError(`Environment variable "${name}" is not defined but is marked as required, aborting.`);}returnprocess.env[name];};
Previously, I was doing the same but manually:
// For each variableexportconstAPI_URL=process.env.API_URL||'http://localhost:8080/';
This refactoring broke the build, since dotenv-webpack only populates explicit variables like process.env.API_URL and not process.env[name] where name = "API_URL".
Would it be possible to add a configuration flag to allow loading all variables defined in the env file, and replacing the whole process.env? Something like
newDotenvPlugin({// load variables from this filepath: envPath,// inject ALL variables, not only the variables explicitly usedloadAllVariables: true,})
The text was updated successfully, but these errors were encountered:
Unfortunately this has been extensively tested. Here you can see my notes as to why this simply isn't possible and the problem is primarily due to webpack: #70 (comment).
@dmca-glasgow sounds like a workaround might be available, but unfortunately this will have to be left alone.
I'm going to close this as its a duplicate of #70 but let me know if you disagree and i'll be happy to open this back up.
I recently refactored my config logic to use the following code:
Previously, I was doing the same but manually:
This refactoring broke the build, since
dotenv-webpack
only populates explicit variables likeprocess.env.API_URL
and notprocess.env[name]
wherename = "API_URL"
.Would it be possible to add a configuration flag to allow loading all variables defined in the env file, and replacing the whole
process.env
? Something likeThe text was updated successfully, but these errors were encountered: