如何在 Nuxt 中为 .env 文件指定另一个目录或名称

kis*_*ssu 2 vue.js nuxt.js

我不想遵循将环境变量(.env文件)放在 Nuxt 项目的根目录中的约定。

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).

kis*_*ssu 6

Looking at this answer: https://github.com/nuxt/nuxt.js/issues/8331#issuecomment-727533175

You can specify a different location and name if you'd like, with the following

yarn dev --dotenv variables/.env_file
Run Code Online (Sandbox Code Playgroud)

With the following structure

在此输入图像描述

Of course, this will work with yarn generate and yarn build.