-
-
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
Use environment variables inside nuxt.config.js #2998
Comments
@javialon26 Thanks! I know about |
How do you define if it is dev or prod mode if you don't set
|
@husayt I thought about some "default" settings (nuxt => development, build & start => production) |
@manniL Actually digging deeper I realised this can be a big issue. The way it works now NODE_ENV is defined after processing nuxt.config.js. That means This seems like a bug to me. |
This seems to be resolved in next version. |
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. |
Hey!
Description
I'm currently trying to set several config parameters depending on whether nuxt.js is launched in dev or production mode. To accomplish this, I haven't changed any environment variables before starting nuxt.
Unfortunately, the following won't work (using the axios module) by default:
If I use
console.log(process.env.NODE_ENV)
in thenuxt.config.js
file, it's undefined (if not set before)Current possible solution
I only came up with one solution for it:
Set env variables before starting
We could update the package.json scripts to include NODE_ENV or set it manually through the console.
The former blocks "overriding" ENV through the command line, the latter is quite tedious.
Use dotenv module
Also a way to deal with it, and highly customizable. Still, there should be an easier way to define the "default" configuration which would be enough in many use-cases.
Other solutions?
Are there better ways to accomplish similar behavior easier?
By default, NODE_ENV is set depending on the nuxt mode (
nuxt dev
= development, production otherwise), but I guess this happens after interpreting the config.Could we use
extend()
for it? 🤔Related
https://github.com/nuxt/nuxt.js/blob/dev/lib/builder/webpack/server.config.js#L50
#1386
The text was updated successfully, but these errors were encountered: