Skip to content

Commit

Permalink
fix: put import meta fallback keys after define
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 3, 2022
1 parent 08fe0fa commit 836040c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/define.ts
Expand Up @@ -39,6 +39,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
// during dev, import.meta properties are handled by importAnalysis plugin.
// ignore replace import.meta.env in lib build
const importMetaKeys: Record<string, string> = {}
const importMetaFallbackKeys: Record<string, string> = {}
if (isBuild) {
const env: Record<string, any> = {
...config.env,
Expand All @@ -47,7 +48,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
for (const key in env) {
importMetaKeys[`import.meta.env.${key}`] = JSON.stringify(env[key])
}
Object.assign(importMetaKeys, {
Object.assign(importMetaFallbackKeys, {
'import.meta.env.': `({}).`,
'import.meta.env': JSON.stringify(config.env),
'import.meta.hot': `false`
Expand All @@ -63,6 +64,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
...(replaceProcessEnv ? processNodeEnv : {}),
...importMetaKeys,
...userDefine,
...importMetaFallbackKeys,
...(replaceProcessEnv ? processEnv : {})
}

Expand Down

0 comments on commit 836040c

Please sign in to comment.