Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add envFile to configuration. #248

Open
sgolovine opened this issue Aug 13, 2023 · 0 comments
Open

Feature Request: Add envFile to configuration. #248

sgolovine opened this issue Aug 13, 2023 · 0 comments

Comments

@sgolovine
Copy link

Is your feature request related to a problem? Please describe.

Often times when setting up this plugin, I have to fight the automatic resolution of env files. On one project for example i have a file called .env which contains all local variables and an .env.dev that has all dev variables (and an .env.prod, etc). Due to the default behavior of this plugin, variables in .env overwrite those in .env.dev when trying to build the api for dev.

Describe the solution you'd like

I have been using a patch in my projects which adds an envFile configuration. When specified, the default resolution behavior is ignored and the env file that is specified is used. In a configuration it looks like this:

custom:
  dotenv:
    envFile: ".env.dev"

The patch is pretty simple and looks like this:

diff --git a/node_modules/serverless-dotenv-plugin/src/index.js b/node_modules/serverless-dotenv-plugin/src/index.js
index 2b0f24c..dd8e54c 100644
--- a/node_modules/serverless-dotenv-plugin/src/index.js
+++ b/node_modules/serverless-dotenv-plugin/src/index.js
@@ -104,7 +104,7 @@ class ServerlessPlugin {
     }
 
     // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
-    const dotenvFiles = [
+    const dotenvFiles = !!this.config.envFile ? [this.config.envFile] : [
       `.env.${env}.local`,
       `.env.${env}`,
       // Don't include `.env.local` for `test` environment

Describe alternatives you've considered

I currently have not found an alternative and rely on the patch.

Additional context

I will do all the required dev work and open a PR for this feature. Opening this feature request to determine if the core devs of this project want this feature.

@sgolovine sgolovine changed the title Add envFile to configuration. Feature Request: Add envFile to configuration. Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant