gpt4 book ai didi

javascript - dotenv-webpack 是否将 .env 中的所有环境变量暴露给前端?

转载 作者:搜寻专家 更新时间:2023-10-31 22:44:58 26 4
gpt4 key购买 nike

我正在构建一个应用程序,该应用程序具有用于某些 API 的公钥和用于其他 API 的私钥。我想将它们全部存储在我的单个 .env 文件中,并使用 dotenv 向我的服务器和 dotenv-webpack 提供私钥> 为我的公共(public)前端 javascript 提供公钥。使用这个包会让我的私钥在我的 javascript 中可用,还是只会使用它需要的私钥?

例子:

# .env file
public_key="12345"
private_key="45678"

这个需要在前端访问

// javascript file on front end
var publicKey = process.env.public_key

但是我想把这个隐藏起来

// javascript file in node.js
var privateKey = process.env.private_key

我正在考虑使用的包是这个: https://www.npmjs.com/package/dotenv-webpack

最佳答案

plugin 的 github 页面指出:

dotenv-webpack wraps dotenv and Webpack.DefinePlugin. As such, it overwrites existing any existing DefinePlugin configurations. Also, like DefinePlugin, it does a text replace in the resulting bundle for any instances of process.env.

Your .env files can include sensitive information. Because of this,dotenv-webpack will only include defined environment variables in the final bundle.

所以它是安全的。它只会公开您在代码中实际使用的环境变量。

关于javascript - dotenv-webpack 是否将 .env 中的所有环境变量暴露给前端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41656354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com