Skip to content

Add exports map with ESM variant #67

Closed
@lukeed

Description

@lukeed

It'd be nice to offer a supplemental ESM build that's linked via:

  • "module" in package.json
  • the import key inside each exports entry (inside package.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions