Skip to content

Commit

Permalink
Fix env vars not working for users without .env files
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Oct 4, 2024
1 parent 263a08d commit 4319e10
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions programs/develop/webpack/plugin-compilation/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ export class EnvPlugin {

// Ensure default environment variables are always available:
// - EXTENSION_PUBLIC_BROWSER
// - EXTENSION_PUBLIC_ENV_MODE
// - EXTENSION_PUBLIC_MODE
filteredEnvVars['process.env.EXTENSION_PUBLIC_BROWSER'] = JSON.stringify(
this.browser
)
filteredEnvVars['import.meta.env.EXTENSION_PUBLIC_BROWSER'] =
JSON.stringify(this.browser)
filteredEnvVars['process.env.EXTENSION_PUBLIC_ENV_MODE'] =
JSON.stringify(mode)
filteredEnvVars['import.meta.env.EXTENSION_PUBLIC_ENV_MODE'] =
filteredEnvVars['process.env.EXTENSION_PUBLIC_MODE'] = JSON.stringify(mode)
filteredEnvVars['import.meta.env.EXTENSION_PUBLIC_MODE'] =
JSON.stringify(mode)

// Apply DefinePlugin to expose filtered variables
Expand All @@ -101,7 +100,7 @@ export class EnvPlugin {

// Replace environment variables in the format $EXTENSION_PUBLIC_VAR
fileContent = fileContent.replace(
/$EXTENSION_PUBLIC_[A-Z_]+/g,
/\$EXTENSION_PUBLIC_[A-Z_]+/g,
(match) => {
const envVarName = match.slice(1) // Remove the '$'
const value = combinedVars[envVarName] || match
Expand Down

0 comments on commit 4319e10

Please sign in to comment.