CreateReactApp 文档显示您可以使用有限数量的 .env 文件。 https://create-react-app.dev/docs/adding-custom-environment-variables/#adding-development-environment-variables-in-env
我想在其他环境中使用更多 .env 文件,但.env.development
总是被使用。
如何使用其他文件?我找到了这篇文章,但它对我不起作用。 https://medium.com/@tacomanator/environments-with-create-react-app-7b645312c09d
我正在使用react-scripts
v3.4.1
Github Action 类似功能的等效配置是什么,如下命令:
env-cmd -f .env cypress run --component
Run Code Online (Sandbox Code Playgroud)
我尝试将一个环境变量导入到 Github Action 中,但不起作用:
env:
CYPRESS_PUBLIC_PATH: /public/
Run Code Online (Sandbox Code Playgroud)
因此,我更喜欢加载 env 文件并直接由应用程序/cypress 使用,而不是一一定义 env 变量。
我找不到任何可以在 Github Action 中加载一个 env 文件的文档。或者也许有一种方法可以在 Github Action 中运行上面完全相同的代码?
更新:我按照@Maddie.Squerciati的指示在Cypress配置上定义env文件,它在我的本地工作,但是github操作仍然无法识别/使用env文件。
这是我的 github 操作配置:
name: Cypress
uses: cypress-io/github-action@v5
with:
config-file: cypress.config.js
command: npm run cy:run-unit
component: true
record: false
parallel: false
browser: chrome
Run Code Online (Sandbox Code Playgroud) environment-variables cypress env-file github-actions env-cmd