vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
69.02k stars 6.24k forks source link

Respect `conditions` arg from node #11838

Open sxzz opened 1 year ago

sxzz commented 1 year ago

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.

sapphi-red commented 1 year ago

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

bluwy commented 1 year ago

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

sxzz commented 1 year ago

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

bluwy commented 1 year ago

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.