Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build.target: ['nodeXX'] ignore replace process.env #8843

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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