gpt4 book ai didi

javascript - 使用 .env 文件中的变量来创建 react 应用程序

转载 作者:行者123 更新时间:2023-12-04 10:39:52 25 4
gpt4 key购买 nike

在 .env 文件中使用变量。在创建 react 应用程序。

我正在尝试在其他 env 变量中重新使用 env 变量,这样做是否正确,但我没有得到值。

.env

A=hello
B=${A}/new

最佳答案

重要的是要意识到 env 变量仅在节点环境中可用,而不能在浏览器中使用。

但如果你使用 create-react-app , 它为你做了一些技巧并在浏览器中模拟相同的行为,只有当你把 REACT_APP_ env 变量之前的前缀。

create-react-app文档说 here:

Note: You must create custom environment variables beginning with REACT_APP_. Any other variables except NODE_ENV will be ignored to avoid accidentally exposing a private key on the machine that could have the same name. Changing any environment variables will require you to restart the development server if it is running.

关于javascript - 使用 .env 文件中的变量来创建 react 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59984509/

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