如何在nuxt中为dotenv设置自定义路径

如何在nuxt中为dotenv设置自定义路径

问题描述:

我有以下 nuxt.config.js,其中 srcDir 指向main-app";我已经将 .env 放在它外面.那么在nuxt.config.js中,如何在第1行设置自定义路径

I have the following nuxt.config.js, where in the srcDir is pointing to "main-app" and I have placed the .env outside of it. So in the nuxt.config.js, how can set the custom path in line 1

require('dotenv').config({ path: '../.env' })

这样我的 process.env 就可以工作了

such that my process.env works

还有nuxt.config.js中的buildModules如下

Also the buildModules in nuxt.config.js is as follows

buildModules: ["@nuxtjs/fontawesome", "@nuxtjs/dotenv"],

其实我需要在 buildModules 部分设置 env 的 live path 就像下面这样

Actually I need to set the live path of the env in the buildModules section just like follows

 buildModules: ["@nuxtjs/fontawesome", ['@nuxtjs/dotenv', { path: './' }]],