Can i set `.env` file path inside `nuxt.config.ts`?
I know I can use
yarn dev --dotenv ../.env
. But I want to define this inside nuxt.config.ts
. Is this possible?6 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yes that works. But having an option in
nuxt.config.ts
supports DRY principle.
In my case I want to have a base
Layer, which imports all .env
variable. Layers that extend the base
Layer should not have to do this again.
Also I think it's more convenient to have all options available in nuxt.config.ts
that are available in the package.json
, like --dotenv
.Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Interesting approach! I saw the
c12
with setupDotenv
part too in the nuxt code. Was hoping for a defined api instead of a "hacky" like solution.
I guess I will just add --dotenv ../.env
to every script I need. Currently it seems to be the safest and most clean way to accomplish it.Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@Pratham Interesting approach that could fix my problem as well. However - similar to what you said - it's just way safer and future proof to do it in each
package.json
for now. Even if it includes some copy-paste. 😄
We use the .env
-file only for local development. In a staging and production deployment, the environment variables are added to the docker container, no .env
-file there.
I would love to see an easy API:
AFAIK, this was possible in earlier versions of Nuxt.