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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load nuxt config with different envName for env-specific configs #357

Open
manniL opened this issue Mar 10, 2024 · 8 comments
Open

Load nuxt config with different envName for env-specific configs #357

manniL opened this issue Mar 10, 2024 · 8 comments

Comments

@manniL
Copy link
Member

manniL commented Mar 10, 2024

Hey all 馃憢

c12 provides us with the amazing opportunity to add env-specific configs to the nuxt config (also covered in my video), therefore relying on NODE_ENV by default. While it is technically possible to change the envName value, e.g. by patching the CLI or similar, it would be nice to have some kind of flag which changes the envName to a different env variable, such as TARGET, APP_ENV etc.

@manniL manniL changed the title Run nuxt with different envName for env-specific configs Load nuxt config with different envName for env-specific configs Mar 10, 2024
@pi0
Copy link
Member

pi0 commented Mar 10, 2024

Can you share more context in what common usecases this might be useful to use something different from NODE_ENV?

@fmoessle
Copy link

fmoessle commented Mar 10, 2024

E.g. deploying a project in a staging environment. Here I want the NODE_ENV to be "production" but need some other variable to differentiate between staging and production. We currently use process.env.TARGET for that and manually select and merge custom config-files depending on process.env.TARGET.

We are not the only ones facing this issue (https://www.youtube.com/watch?v=sCzO4fpKOW4) but it's possible I just don't get how to solve this in a more nuxt-fashioned way.

@manniL
Copy link
Member Author

manniL commented Mar 10, 2024

In addition to @fmoessle's comment, build sets the NODE_ENV always to production, leaving no room for further options.

@pi0
Copy link
Member

pi0 commented Mar 10, 2024

In addition to @fmoessle's comment, build sets the NODE_ENV always to production, leaving no room for further options.

This is a bug we might try to fix first.

@manniL
Copy link
Member Author

manniL commented Mar 10, 2024

In addition to @fmoessle's comment, build sets the NODE_ENV always to production, leaving no room for further options.

This is a bug we might try to fix first.

I think this is intentional, isn't it? 馃憖

`Changing \`NODE_ENV\` from \`${currentEnv}\` to \`${targetEnv}\`, to avoid unintended behavior.`,

image

@fmoessle
Copy link

I think not using process.env.NODE_ENV with production when building the nuxt application is not a good idea. There are a lot of packages that behave differently when process.env.NODE_ENV is set to production (e.g. Node docs).

So as @manniL pointed out, process.env.NODE_ENV should not be used here.

@pi0
Copy link
Member

pi0 commented Mar 11, 2024

I think this is intentional, isn't it? 馃憖

It is intentionally set because tools (notably postcss stuff) hardly depend on NODE_ENV==='production' to optimize properly. (@fmoessle you are right. only for clarification, I made that decision as well so I'm aware of it ;)

It is not intentional that we don't respect it for c12 configuration env.

@maximepvrt
Copy link

And allow to use environment overrides for all custom environments (ex: staging)

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

No branches or pull requests

4 participants