Skip to content

Commit 91777d5

Browse files
committed
refactor(web): improve environment file loading logic in webpack config
This commit refines the environment file loading logic in the webpack configuration. It updates variable names for clarity, ensures that the correct environment file is used, and enhances logging for build processes. Additionally, it maintains flexibility by allowing environment variables to be provided via process.env when the specified file is not found.
1 parent 1d7172f commit 91777d5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/web/webpack.config.mjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,28 @@ const loadEnvFile = (envName) => {
1919
test: null, // test environment doesn't require env file
2020
};
2121

22-
const file = map[envName] || ".env.local";
22+
const envFile = map[envName];
2323

2424
// Skip file loading for test environment or if file is explicitly null
25-
if (envName === "test" || file === null) {
25+
if (envName === "test" || envFile === null) {
2626
console.log(
2727
`Skipping env file load for ${envName} environment (using process.env)`,
2828
);
2929
return;
3030
}
3131

32-
const fullPath = _resolve(_dirname, "..", "..", "packages", "backend", file);
32+
const fullPath = _resolve(
33+
_dirname,
34+
"..",
35+
"..",
36+
"packages",
37+
"backend",
38+
envFile,
39+
);
3340

3441
if (fs.existsSync(fullPath)) {
35-
console.log(`Creating a ${envName} build using ${file} ...`);
36-
dotenv.config({ path: fullPath });
42+
console.log(`Creating a ${envName} build using ${envFile} ...`);
43+
dotenv.config({ path: fullPath, override: true });
3744
} else {
3845
// Only warn, don't exit - allow environment variables to be provided via process.env (e.g., in CI)
3946
console.warn(
@@ -45,7 +52,7 @@ const loadEnvFile = (envName) => {
4552
export default (env, argv) => {
4653
const IS_DEV = argv.mode === "development";
4754

48-
const ENVIRONMENT = argv.nodeEnv || "local";
55+
const ENVIRONMENT = argv.nodeEnv;
4956
loadEnvFile(ENVIRONMENT);
5057

5158
const GLOBAL_SCSS = resolvePath("src/common/styles/index.scss");

0 commit comments

Comments
 (0)