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

feat: add `dynamic` option #56

Closed
wants to merge 2 commits into from

Conversation

Projects
None yet
2 participants
@bcanseco
Copy link

bcanseco commented Mar 19, 2019

This PR adds support for a new dynamic option in this plugin's configuration. This is not a breaking change.

Use case

My team and I use this library a lot across many repositories. Some of us develop on multiple computers with different OS' and different file directories. Since our .env files are git-ignored, we each have to individually update them whenever a key changes.

dynamic would allow each developer to set path to the name of an environment variable that contains the actual path of the .env file.

Example

Using something like Box, Dropbox, Google Drive, or a shared network drive, each developer has access to the same shared folder, but at potentially different paths on their computer.

  • e.g. Michael accesses it at C:/Users/Michael/work/shared
  • e.g. Sarah access it at /home/sarah/shared

The shared folder contains a .env file:

API_KEY=123

A project that depends on babel-plugin-dotenv-import sets the following config:

{
  "plugins": [
    ["dotenv-import", {
      "path": "SHARED_ENV_LOCATION",
      "dynamic": true
    }]
  ]
}

Then the project's README.md would include something like this:

# Getting started
1. `npm install`
2. Set your `SHARED_ENV_LOCATION` environment variable to the location of our `.env` file.
3. `npm start`

bcanseco added some commits Mar 19, 2019

@bcanseco

This comment has been minimized.

Copy link
Author

bcanseco commented Mar 19, 2019

Once again I realized babel already has a good way to do this with babelrc.js, so I'm closing this.

module.exports = {
  plugins: [
    ['dotenv-import', {
      path: process.env.SHARED_ENV_LOCATION
    }]
  ]
};

@bcanseco bcanseco closed this Mar 19, 2019

@tusbar

This comment has been minimized.

Copy link
Owner

tusbar commented Mar 19, 2019

https://github.com/motdotla/dotenv/blob/master/lib/env-options.js

I haven’t tried it, but there’s a good chance you can use DOTENV_CONFIG_PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.