Skip to content

Commit 29d378d

Browse files
tyler-daneCopilot
andauthored
refactor(web): improve environment file loading logic in webpack config (#1187)
* 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. * Update packages/web/webpack.config.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/web/webpack.config.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/web/webpack.config.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1d7172f commit 29d378d

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/web/webpack.config.mjs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,35 @@ 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

24+
// Handle unmapped environment names explicitly
25+
if (typeof envFile === "undefined") {
26+
console.error(
27+
`Error: Unrecognized environment name '${envName}'. Valid options are: ${Object.keys(map).join(", ")}.`
28+
);
29+
return;
30+
}
2431
// Skip file loading for test environment or if file is explicitly null
25-
if (envName === "test" || file === null) {
32+
if (envName === "test" || envFile === null) {
2633
console.log(
2734
`Skipping env file load for ${envName} environment (using process.env)`,
2835
);
2936
return;
3037
}
3138

32-
const fullPath = _resolve(_dirname, "..", "..", "packages", "backend", file);
39+
const fullPath = _resolve(
40+
_dirname,
41+
"..",
42+
"..",
43+
"packages",
44+
"backend",
45+
envFile,
46+
);
3347

3448
if (fs.existsSync(fullPath)) {
35-
console.log(`Creating a ${envName} build using ${file} ...`);
36-
dotenv.config({ path: fullPath });
49+
console.log(`Creating a ${envName} build using ${envFile} ...`);
50+
dotenv.config({ path: fullPath, override: true });
3751
} else {
3852
// Only warn, don't exit - allow environment variables to be provided via process.env (e.g., in CI)
3953
console.warn(

0 commit comments

Comments
 (0)