Env variables not working
Using Nuxt 3.18.1.
Hi! I've been struggling with an env variable. I can't seem to make it work when running the preview (npm run build && npm run preview). Locally, it works as it should. Basically, I want a variable to be true on dev and false on prod. For testing purposes, I have it set to true in .env.production, so I can see in an if statement if it works. Here's my current code:
.env.development:
.env.production:
nuxt.config.js:
/api/example/[id].ts:
I run
Could I please get some help with this? I'm trying to understand how env variables work. I've read through documentation and research but I can't seem to get it right.
TIA!
Hi! I've been struggling with an env variable. I can't seem to make it work when running the preview (npm run build && npm run preview). Locally, it works as it should. Basically, I want a variable to be true on dev and false on prod. For testing purposes, I have it set to true in .env.production, so I can see in an if statement if it works. Here's my current code:
.env.development:
NUXT_PUBLIC_USE_MOCK_DATA=true.env.production:
NUXT_PUBLIC_USE_MOCK_DATA=truenuxt.config.js:
/api/example/[id].ts:
I run
npm run build && npm run preview and useMockData is always false/falsey.Could I please get some help with this? I'm trying to understand how env variables work. I've read through documentation and research but I can't seem to get it right.
TIA!
