Current project structure:
…
-src
-.env.development
-.env.uat
-.env.production
-webpack
-webpack.base.js
-webpack.dev.js
-webpack.uat.js
-webpack.prod.js
In webpack, I set new Dotenv({ path: "./.env.development" }) for development environment, etc
webpack.dev.js
const { merge } = require("webpack-merge");
const base = require("./webpack.base");
const Dotenv = require("dotenv-webpack");
module.exports = merge(base, {
mode: "development",
output: {...},
devServer: {...},
plugins: [new Dotenv({ path: "./.env.development" })],
});
webpack.uat.js
const { merge } = require("webpack-merge");
const base = require("./webpack.base");
const Dotenv = require("dotenv-webpack");
module.exports = merge(base, {
mode: "production",
output: {...},
module: {...},
plugins: [
new Dotenv({ path: "./.env.uat" }),
...
],
});
webpack.prod.js
const { merge } = require("webpack-merge");
const base = require("./webpack.base");
const Dotenv = require("dotenv-webpack");
module.exports = merge(base, {
mode: "production",
output: {...},
module: {...},
plugins: [
new Dotenv({ path: "./.env.prod” }),
...
],
});
package.json
"scripts": {
"build:uat": "cross-env NODE_ENV=uat webpack --config ./webpack/webpack.uat.js",
"build": "webpack --config ./webpack/webpack.prod.js",
},
I am going to use Gitlab CI and CI/CD, so I am thinking how to handle the .env variables.
I’ve added environment variables in gitlab Settings > CI/CD > Variables.
After adding it, I have no idea how to proceed to next step.
Also, how to I test if the environment variables is set in gitlab?