How to specify another directory or name for the .env file in Nuxt

Viewed 1058

I don't want to follow the convention of putting my environment variable (.env file) at the root directory of my Nuxt project.

How can I achieve another directory or even name for it without using the @nuxtjs/dotenv module? (I know this one is already baked into Nuxt since v2.13 and hence, not needed anymore).

2 Answers

I got no luck with the --dotenv flag, so I'm just using replacing .env with the desired contents upon build or serve, like cp .env.xxx .env && yarn dev. Not the prettiest, but good enough.

In your case the command would be cp variables/.env_file .env && yarn dev.

Related