mrsteele / dotenv-webpack

A secure webpack plugin that supports dotenv and other environment variables and only exposes what you choose and use.
MIT License
1.3k stars 76 forks source link

feat: custom prefix #482

Closed vuode closed 2 years ago

vuode commented 2 years ago

Custom prefix

In #480 @niieani suggested a great feature—ability to use custom prefixes.

Here is my attempt to implement this feature

// default
new Dotenv({})
// process.env.PORT

// explicit
new Dotenv({
  prefix: 'process.env.'
})
// process.env.PORT

// custom prefix
new Dotenv({
  prefix: `import.meta.env.`
})
// import.meta.env.PORT
mrsteele commented 2 years ago

I haven’t forgotten about this (promise, just went on a vacation with the wife and so technology was mostly a no-no).

mom wrestling with this a bit because I’m wondering if we should rethink the last breaking change for this approach. Should we assume your prefix is “process.env.”? Do we let you set it to nothing if you want nothing? Do we try to make them compatible with one another?

I’m worried about the complexities with juggling the former system which makes some assumptions and adds a bit of confusion with this proposed system which is meant to make things a little more explicit. I like things being as easy as possible to get started, but am also a big fan of giving power to the developer to configure what they need when they need it.

Thoughts or ideas or opinions would be appreciated. Also, appreciate the patience (and my wife does too).

niieani commented 2 years ago

I'm fine with this as is. Perhaps being explicit has the additional benefit in that process is usually not a global in the browser environment, so the assumption that it's the default is a bit odd, and only due to it being the legacy. In that respect, using import.meta.env. is a bit more sound, because import.meta is actually a standard that browsers with support for modules have to abide by. Changing the default would be a breaking change though (which I'm fine with). Honestly, I think the final decision here is not that important, as long as it's documented.

mrsteele commented 2 years ago

Yeah, good point. I'm going to push this out today. Hopefully all systems work 🤞 .

Thank you so much for your patience through all of this @niieani and @vuode. I hope the community enjoys this added feature 🎉

mrsteele commented 2 years ago

@vuode did you mean to close this? It didn't get merged.

vuode commented 2 years ago

@vuode did you mean to close this? It didn't get merged.

Sorry, no, wrongly clicked the button

github-actions[bot] commented 2 years ago

:tada: This PR is included in version 7.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: