所以我在我的仓库中有一个我正在处理的react / typescript应用程序,在我的仓库中有一个.env文件,我忽略了它,这样我的秘密就不会暴露了。重要的.env-example文件环境变量进行配置。我的问题是,由于我没有将.env文件推送到我的存储库中,因此当我通过Google App引擎部署应用程序时(这是在gitlab-ci.yml文件的部署阶段完成的),这些环境变量会在生产环境中不存在,我需要它们才能使我的应用程序正常工作,因为我在webpack.config.js文件中执行了类似的操作。
const dotenv = require('dotenv').config({ path: __dirname + '/.env' });
Run Code Online (Sandbox Code Playgroud)
然后
new webpack.DefinePlugin({
'process.env': dotenv.parsed
})
Run Code Online (Sandbox Code Playgroud)
这是我的.gitlab-ci文件,以防万一有人在这里看到。
cache:
paths:
- node_modules/
stages:
- build
- test
- deploy
Build_Site:
image: node:8-alpine
stage: build
script:
- npm install --progress=false
- npm run-script build
artifacts:
expire_in: 1 week
paths:
- build
Run_Tests:
image: node:8-alpine
stage: test
script:
- npm install --progress=false
- npm run-script test
Deploy_Production:
image: google/cloud-sdk:latest
stage: deploy
environment: Production
only: …Run Code Online (Sandbox Code Playgroud)