-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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: automatically include env variables starting with NUXT_ENV_ #3862
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. We have to document it too.
@pi0 That's why I haven't ticked the box yet :P |
lib/common/options.js
Outdated
@@ -161,6 +161,10 @@ Options.from = function (_options) { | |||
vueConfig.performance = options.dev | |||
} | |||
|
|||
// merge custom env with variables | |||
const eligibleEnvVariables = _.pick(process.env, Object.keys(process.env).filter(k => k.startsWith('NUXT_ENV_'))) | |||
options.env = Object.assign(eligibleEnvVariables, options.env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't env variables override options.env
? Maybe it would be better to use Object.assign({}, options.env, eligibleEnvVariables)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't certain which behavior would be more appropriate.
On the one hand, it feels like someone "automatically injected" should have an option to get overridden.
On the other hand, env variables are way more "closer" to the system...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last point would be consistency. I'll change it to the suggested value
Codecov Report
@@ Coverage Diff @@
## dev #3862 +/- ##
==========================================
+ Coverage 97.57% 97.57% +<.01%
==========================================
Files 18 18
Lines 1196 1198 +2
Branches 328 328
==========================================
+ Hits 1167 1169 +2
Misses 28 28
Partials 1 1
Continue to review full report at Codecov.
|
17b11e7
to
a5b026e
Compare
5e0d878
to
7921d17
Compare
7921d17
to
82f7eff
Compare
Love this PR :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
If you don't want to add all
env variables
to yournuxt.config.js
you now can prefix them withNUXT_ENV_
to get them automatically included in theprocess.env
object.Example:
NUXT_ENV_TEST=awesome nuxt build && nuxt start
process.env.NUXT_ENV_TEST //awesome
Types of changes
Checklist: