Skip to content

Commit

Permalink
feat: build.target: ['nodeXX'] ignore replace process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Jul 4, 2022
1 parent f9b5c14 commit bcf7967
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/vite/src/node/plugins/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ const isNonJsRequest = (request: string): boolean => nonJsRe.test(request)
export function definePlugin(config: ResolvedConfig): Plugin {
const isBuild = config.command === 'build'
const isBuildLib = isBuild && config.build.lib
let isTargetNode: boolean | undefined

if (
Array.isArray(config.build.target) &&
config.build.target.find((e) => e.startsWith('node'))
) {
isTargetNode = true
} else if (
typeof config.build.target === 'string' &&
config.build.target.startsWith('node')
) {
isTargetNode = true
}

// ignore replace process.env in lib build
const processEnv: Record<string, string> = {}
Expand Down Expand Up @@ -58,7 +71,8 @@ export function definePlugin(config: ResolvedConfig): Plugin {
function generatePattern(
ssr: boolean
): [Record<string, string | undefined>, RegExp | null] {
const replaceProcessEnv = !ssr || config.ssr?.target === 'webworker'
const replaceProcessEnv =
!(ssr || isTargetNode) || config.ssr?.target === 'webworker'

const replacements: Record<string, string> = {
...(replaceProcessEnv ? processNodeEnv : {}),
Expand Down

0 comments on commit bcf7967

Please sign in to comment.