Add `exports` map with ESM variant
lukeed opened this issue · 1 comments
lukeed commented
It'd be nice to offer a supplemental ESM build that's linked via:
"module"
inpackage.json
- the
import
key inside eachexports
entry (insidepackage.json
too)
This'd end up looking something like:
{
// ...
"module": "dist/index.mjs",
"main": "dist/index.js",
// ...
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./from": {
"require": "./from/index.js",
"import": "./from/index.mjs"
}
}
// ...
}
This allows for native ESM resolution in Node.js (12.x and >=14) in supporting environments w/o sacrificing CommonJS (default) support. Also allows bundler(s) to pick up the ESM entry, too.
There's one gotcha – Node 13.0 thru 13.7 don't support this version of exports
.
This can be patched – but only if you decide to keep the default exports (module.exports
/ export default
) that you currently have. This means that the the addition remains non-breaking, even w/ these Node versions.
I can PR these changes if desired.
jimmywarting commented
The v3 have switched to ESM - no longer provide a commonjs variant