Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions packages/web/webpack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@ const loadEnvFile = (envName) => {
test: null, // test environment doesn't require env file
};

const file = map[envName] || ".env.local";
const envFile = map[envName];

// Handle unmapped environment names explicitly
if (typeof envFile === "undefined") {
console.error(
`Error: Unrecognized environment name '${envName}'. Valid options are: ${Object.keys(map).join(", ")}.`
);
return;
}
// Skip file loading for test environment or if file is explicitly null
if (envName === "test" || file === null) {
if (envName === "test" || envFile === null) {
console.log(
`Skipping env file load for ${envName} environment (using process.env)`,
);
return;
}

const fullPath = _resolve(_dirname, "..", "..", "packages", "backend", file);
const fullPath = _resolve(
_dirname,
"..",
"..",
"packages",
"backend",
envFile,
);

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