Respect `conditions` arg from node
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.
It seems there's a issue for exposing the internal method that parses the command line options: https://github.com/nodejs/node/issues/36935
This is now supported through ssr.resolve.externalConditions. We could revisit this again if Node exposes the API.
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
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.