-
Notifications
You must be signed in to change notification settings - Fork 14
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
Making exports viable for CommonJS #26
Comments
Wouldn't it be easier to create the same general idea for CommonJS, just without the locked down default? It feels a bit fragile to allow this level of context-sensitive logic inside of {
"./public/": {
"esm": "./lib/api",
"cjs": "./src/api"
},
"./public/data/": "./data"
} Does this mean As an alternative, I would see the following as a lot nicer: {
"exports": {
".": "./main.mjs",
"./x": "./x.mjs"
},
"main": {
".": "./main.js",
"./x": "./x.js"
}
} |
If we match
Note we can't turn main into an object as that breaks backwards compat meaning no one would do it. As for the suggestion of using a different key for CommonJS, I feel like there is a nice synnergy here with the "browser" mapping needs. It is a proven use case that we need to fork browser mappings sometimes. If we could support a "browser" condition just like "cjs" then we solve the browser problem as well very nicely. |
What I like about The problem of implicitly aliasing multiple files, including extensions, is something that i think should be different. (Note that the "browser" field only provides 1:1 mapping, even in object form) |
|
At today's meeting there was interest in upstreaming this proposal already to CommonJS.
If we do this, we need to have the ability to provide "exports" differently between ESM and CJS, in order to handle dual mode use cases (if we want that!).
I will start off with a proposal here, feedback and suggestions further are welcome.
The idea would be to branch based on a "condition" in exports:
would still be supported fine, and apply for both CommonJS and ESM loaders.
But then we would also support an object form to branch between the two:
The nice thing about this approach is the branch conditionals could also be extended to things like "browser", "node", "production", "development" allowing a general conditional subpathing based on the environment.
Do we want to move forward with a proposal along these lines? Perhaps we should set up a call to discuss further?
The text was updated successfully, but these errors were encountered: