【发布时间】:2020-12-30 01:47:04
【问题描述】:
我在 Vue 中为前端构建一个应用程序,在后面为 Node 构建一个应用程序,并且我正在将环境变量用于私有 API 密钥。 .env 文件位于我的全局项目的根目录中,我在本地使用 Dotenv-Webpack 在我的前面访问它们。
本地一切正常,但是当我在 Heroku 中部署应用程序时,变量是 undefined
这是我项目的结构
client
-> public
-> src
-> components
-> assets
...
...
routes
services
tests
...
.env
这是我的 vue.config.js 的配置
const path = require("path");
const Dotenv = require("dotenv-webpack");
module.exports = {
transpileDependencies: ["vuetify"],
outputDir: path.resolve(__dirname, "../public"),
devServer: {
proxy: "http://localhost:5000"
},
configureWebpack: {
plugins: [
new Dotenv({
path: "../.env", // load this now instead of the ones in '.env'
systemvars: true
})
]
}
};
有人有想法吗?提醒一下,它可以在本地访问我的组件中的 .env,但不能在我在 Heroku 中部署应用程序时访问
【问题讨论】:
标签: node.js heroku webpack environment-variables