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 env-flag for env-specific config (#357) #424

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tillsanders
Copy link

This PR is proposing to add a new --env [name] attribute to Nuxi. The attribute will be passed to the envName option of the c12 library. This adds the ability to support environment overrides (environment-specific configuration) for custom environments. Currently, c12 supports that and the types of the nuxt configuration file are aware of that, but there is no way to actually use custom environments, because NODE_ENV cannot be set to values other than production or development. This PR closes the gap, making deployments to different environments easier.

See #357.

Should this be approved, I would be happy to amend the documentation accordingly.

@MickL
Copy link

MickL commented Jul 20, 2024

Does this PR also apply for the environment overrides set in nuxt.config.ts? So if I set --env preview it will pick up the second one?

export default defineNuxtConfig({
   $production: {
       ignore: ['app/pages/dev'],
       scripts: {
         registry: {
           cloudflareWebAnalytics: true,
         },
       },
   },
   $preview: {
        ignore: ['app/pages/dev'],
   },
});

@@ -27,6 +27,10 @@ export default defineCommand({
type: 'string',
description: 'Path to .env file',
},
env: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more clarity i would suggest to name it envName / --env-name.

--env might also be usable for other purposes in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: i think we can make a shared object similar to how legacyRootDirArgs now i guess since this is arg is shared for all commands.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I appreciate your feedback! I made the necessary changes as you suggested. I noticed that there is a slight inconsistency in the way the flags are named. Some use kebab-case, others lowerCamelCase – e.g. --logLevel and --no-fork. I decided to go with lowerCamelCase as that seems to be the majority and matches the naming in the loadNuxt() function.

I also made a small amendment to the documentation, here: nuxt/nuxt#28909

Please let me know if any other changes are required – looking forward to have this available!

tillsanders added a commit to tillsanders/nuxt that referenced this pull request Sep 10, 2024
Documentation accompanying the PR for Nuxt CLI: nuxt/cli#424 (currently in review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants