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: automatically include env variables starting with NUXT_ENV_ #3862

Merged
merged 1 commit into from
Sep 8, 2018

Conversation

manniL
Copy link
Member

@manniL manniL commented Sep 7, 2018

If you don't want to add all env variables to your nuxt.config.js you now can prefix them with NUXT_ENV_ to get them automatically included in the process.env object.

Example:

  1. Build and start your app. Include the variable in the build step:
    NUXT_ENV_TEST=awesome nuxt build && nuxt start
  2. Call it in your app process.env.NUXT_ENV_TEST //awesome

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

Copy link
Member

@pi0 pi0 left a 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.

@manniL
Copy link
Member Author

manniL commented Sep 7, 2018

@pi0 That's why I haven't ticked the box yet :P
Will submit a PR to the docs and link it here!

@@ -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)
Copy link
Member

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)

Copy link
Member Author

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...

Copy link
Member Author

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-io
Copy link

codecov-io commented Sep 7, 2018

Codecov Report

Merging #3862 into dev will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
lib/common/options.js 96.25% <100%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f879925...82f7eff. Read the comment docs.

@manniL manniL force-pushed the feat-nuxt-env branch 2 times, most recently from 17b11e7 to a5b026e Compare September 7, 2018 20:55
@pi0 pi0 requested a review from clarkdo September 8, 2018 18:53
@manniL manniL force-pushed the feat-nuxt-env branch 2 times, most recently from 5e0d878 to 7921d17 Compare September 8, 2018 20:50
@pi0 pi0 merged commit 1e02195 into nuxt:dev Sep 8, 2018
@manniL manniL deleted the feat-nuxt-env branch September 8, 2018 21:10
@Atinux
Copy link
Member

Atinux commented Sep 13, 2018

Love this PR :)

@lock
Copy link

lock bot commented Oct 31, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants