Skip to content

Commit

Permalink
fix: NODE_ENV was overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Oct 7, 2022
1 parent 9c4e697 commit 1d972cb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/vite/src/node/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export function loadEnv(
})
)

if (parsed['NODE_ENV'] && process.env.VITE_USER_NODE_ENV === undefined) {
// dotenv-expand will replace NODE_ENV with process.env.NODE_ENV
// so we'll deal with VITE_USER_NODE_ENV first
process.env.VITE_USER_NODE_ENV = parsed['NODE_ENV']
Reflect.deleteProperty(parsed, 'NODE_ENV')
}

// let environment variables use each other
expand({
parsed
Expand All @@ -59,12 +66,6 @@ export function loadEnv(
for (const [key, value] of Object.entries(parsed)) {
if (prefixes.some((prefix) => key.startsWith(prefix))) {
env[key] = value
} else if (
key === 'NODE_ENV' &&
process.env.VITE_USER_NODE_ENV === undefined
) {
// NODE_ENV override in .env file
process.env.VITE_USER_NODE_ENV = value
}
}
return env
Expand Down

0 comments on commit 1d972cb

Please sign in to comment.