Skip to content

Commit

Permalink
fix: user define on import.meta.env should apply during dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 11, 2021
1 parent 19f3503 commit 603d57e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@ export async function resolveConfig(

// load .env files
const userEnv = loadEnv(mode, resolvedRoot)
// check if user defined any import.meta.env variables
if (config.define) {
const prefix = `import.meta.env.`
for (const key in config.define) {
if (key.startsWith(prefix)) {
userEnv[key.slice(prefix.length)] = config.define[key]
}
}
}

// Note it is possible for user to have a custom mode, e.g. `staging` where
// production-like behavior is expected. This is indicated by NODE_ENV=production
Expand Down

0 comments on commit 603d57e

Please sign in to comment.