GoogleChromeLabs / GoogleChromeLabs/comlink
Specify `exports` in `package.json
- Dominant language
- TypeScript
- Stars
- 12.8k
- Forks
- 435
- PR merge metrics
- No merged PRs in 30d
Description
Right now, it's not possible to import something like `comlink/node-adapter` and automatically get CJS or ESM depending on the environment.
`node` and some bundlers support:
```json
{
"exports": {
".": {
"require": "dist/umd/comlink.js",
"import": "dist/esm/comlink.mjs",
"types": "dist/umd/comlink.d.ts",
},
"./node-adapter": {
"require": "dist/umd/node-adapter.js",
"import": "dist/esm/node-adapter.mjs",
"types": "dist/umd/node-adapter.d.ts"
}
}
}
```
An alternative would be to add `/node-adapter/package.json` or `/dist/node-adapter/package.json` containing:
```json
{
"main": "dist/umd/node-adapter.js",
"module": "dist/esm/node-adapter.mjs",
"types": "dist/umd/node-adapter.d.ts"
}
```
Does the former seem reasonable? If not, does the latter?
One caveat is that `exports` can//should prevent importing any other files directly, so we'd need more fields if we want to export the minified versions so they can be used directly in `node` or bundlers that support `exports`. (If the minified files are mainly meant for using manually, this is not needed.)
Contributor guide
Assessment
This issue has not been assessed yet.