vite icon indicating copy to clipboard operation
vite copied to clipboard

Respect `conditions` arg from node

Open sxzz opened this issue 2 years ago • 1 comments

Describe the ~~bug~~ feature (it's a feature I guess)

Context: Resolving external deps in vite.config.ts

https://github.com/vitejs/vite/blob/128f09eb0100e80f566e33ca8c55bcd0896d4e38/packages/vite/src/node/config.ts#L983-L984

conditions is always empty, but we can specify a value via node --conditions=dev or NODE_OPTIONS='--conditions=dev' node.

Suggested solution

I suggest that we should read both process.env and process.execArgv, and parse & merge them. It's a bit complex because there are tons of options in Node (and V8).

Alternative

Or we can just use a Regex to match it.

// 3 cases
node --conditions=dev
node --conditions dev
node -C dev

Therefore, I wonder if there is a better solution can this issue.

sxzz avatar Jan 28 '23 11:01 sxzz

It seems there's a issue for exposing the internal method that parses the command line options: https://github.com/nodejs/node/issues/36935

sapphi-red avatar Jan 29 '23 11:01 sapphi-red

This is now supported through ssr.resolve.externalConditions. We could revisit this again if Node exposes the API.

bluwy avatar Nov 09 '23 17:11 bluwy

The issue is not fixed. I want to specify the conditions of external deps in vite.config.ts, not for SSR.

I checked the latest main branch, but nothing changed. https://github.com/vitejs/vite/blob/2687dbbd4e19c86f9888ee784c9b51598e8b79ca/packages/vite/src/node/config.ts#L1046-L1047

sxzz avatar Nov 09 '23 22:11 sxzz

Ah ok I misread it. I'm not really sure still if there's much we can do without the node api, or we have to rework how we load config files.

bluwy avatar Nov 10 '23 03:11 bluwy