Skip to content

Commit

Permalink
Revert "fix: don't replace NODE_ENV in vite:client-inject (#6935)"
Browse files Browse the repository at this point in the history
This reverts commit 2b70003.
  • Loading branch information
patak-dev committed Feb 18, 2022
1 parent 2b70003 commit cfb1426
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/vite/src/node/plugins/clientInjections.ts
Expand Up @@ -40,20 +40,21 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin {
port = path.posix.normalize(`${port}${hmrBase}`)
}

const defines = {
'process.env.NODE_ENV': JSON.stringify(config.mode),
...(config.define || {})
}

return code
.replace(`__MODE__`, JSON.stringify(config.mode))
.replace(`__BASE__`, JSON.stringify(config.base))
.replace(`__DEFINES__`, serializeDefine(defines))
.replace(`__DEFINES__`, serializeDefine(config.define || {}))
.replace(`__HMR_PROTOCOL__`, JSON.stringify(protocol))
.replace(`__HMR_HOSTNAME__`, JSON.stringify(host))
.replace(`__HMR_PORT__`, JSON.stringify(port))
.replace(`__HMR_TIMEOUT__`, JSON.stringify(timeout))
.replace(`__HMR_ENABLE_OVERLAY__`, JSON.stringify(overlay))
} else if (code.includes('process.env.NODE_ENV')) {
// replace process.env.NODE_ENV
return code.replace(
/\bprocess\.env\.NODE_ENV\b/g,
JSON.stringify(config.mode)
)
}
}
}
Expand Down

0 comments on commit cfb1426

Please sign in to comment.