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

Allow overriding config with environment variables #16

Open
pi0 opened this issue May 3, 2022 · 2 comments
Open

Allow overriding config with environment variables #16

pi0 opened this issue May 3, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@pi0
Copy link
Member

pi0 commented May 3, 2022

We can use destr to allow overriding any configuration using process.env.{NAME}_CONFIG_{PATH}.

Let's same NAME is NUXT:

  • NUXT_CONFIG_SSR=false overrides ssr to false
  • NUXT_CONFIG_GENERATE:CRAWLER=true overrides generate.crawler to true
  • NUXT_CONFIG={"ssr": false, "generate": { "crawler": true }} does the same as two above

Notes:

  • defaults option needs to exist in order to enable an env variable to override
  • Same as defu, arrays can be only extended not overridden. We might find a convention for defu to allow this with specific key prefix/suffix.
@rijkvanzanten
Copy link
Contributor

rijkvanzanten commented May 16, 2023

@pi0 We have a need for this as well, so happy to provide a PR if desired 🙂

Before diving into anything though, do you have any more in-depth thoughts/specs on how that should work?

Directus' configuration currently does a similar level of "automagic" type casting and nesting by looking at the env var name (so for example THIS_IS__NESTED="true" becomes { "thisIs": { "nested": true }}, so happy to lift some of that logic into c12 and tweak it for the updated syntax. What's your plan for "multipart" names? Like should NUXT_CONFIG_CAMEL_CASE become { "camelCase": x }? Curious to hear your thoughts! Also happy to chat on Discord / Google Meet or whatever else is most convenient for you 🙂

@AlbanCrepel
Copy link

@pi0 Any update on this issue, or on @rijkvanzanten's proposal ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants