-
Notifications
You must be signed in to change notification settings - Fork 43
Simple conditions flag #537
Comments
I assume the idea would be that they would be similar to |
@jkrems that brings up a good point about prohibiting some values from the CLI |
Would these conditions select for CJS, or ESM? Some folks might but CJS in |
@ljharb I'm not sure I understand the question / workflow |
So, pre-ESM, the "browser" field was "CJS meant to be bundled for the browser", and "main" was "CJS meant to be required by node". In conditions, "require" is for "CJS" and "import" is for "ESM". Which module system is "production" for? |
ljharb: it isn't for a module system, it is for a differing implementation; e.g. load the module with debugging hooks exposed vs not |
@bmeck right, but load the module as ESM, or as CJS? |
@ljharb thats unrelated to even |
@ljharb Conditions can (and in this case likely should) be combined. E.g.: "exports": {
"import": { "development": "./dev.mjs", "default": "./prod.mjs" },
"require": { "development": "./dev.cjs", "default": "./prod.cjs" }
} |
@jkrems now that makes sense to me. Is there even a use case for using dev/prod on the first level of exports, as opposed to the second as you illustrated? |
Depending on how terse you want to be, it can be handy to use it top-level like this: "exports": {
"require": { "development": "./dev.cjs", "default": "./prod.cjs" },
"development": "./dev.mjs",
"default": "./prod.mjs"
} |
You also might have modules you never want to use in production, so top level would be "development" |
This landed on core, closing |
This has now landed as |
@guybedford is |
Since the PR for a
--dev
flag got stalled at nodejs/node#33171 it could still be useful to provide a top-level way to set Node.js conditions like"development"
and"production"
.The simplest proposal then would just be to have a top-level
--conditions
flag:as a comma-separated list of conditions to add to the resolution process.
Perhaps if there is time to discuss this today we can get some feedback before any PR work is attempted.
The text was updated successfully, but these errors were encountered: