Babel: Also publish as modules (instead of compiling to cjs)

Created on 10 Jun 2020  路  1Comment  路  Source: babel/babel

Feature Request

Is your feature request related to a problem?

Would like to be able to consume babel packages directly as modules (as they are written), instead of just cjs. (In my case, may want to import Babel itself into something like snowpack/vite which tries to only support esm). This would be for anything trying to use babel for tooling like the repl/etc so not a common usecase.

Also good that we dogfood what other packages/libraries are doing, even though we aren't really a tool for the browser it would be good to attempt to understand the issues with doing all this anyway.

Describe the solution you'd like

Use package exports. When building we change our config to do modules: false in preset-env. Currently we do "main": "lib/index.js", for most packages.

Could output a whole folder like dist or module instead of lib or output .mjs in the same lib folder.

{
  "main": "./lib/main.js",
  "module": "./lib/module.mjs",
  "exports": {
    ".": {
      "import": "./lib/module.mjs",
      "default": "./lib/main.js"
    },
    "./other": {
      "import": "./lib/other.mjs",
      "default": "./lib/other.js"
    }
  }
}

Describe alternatives you've considered.

Don't think there's an alternative other than consuming the source via github which is difficult because this is a monorepo. We only publish cjs.

enhancement

Most helpful comment

I'm working on this, but it won't happen sooner than Babel 8.

>All comments

I'm working on this, but it won't happen sooner than Babel 8.

Was this page helpful?
0 / 5 - 0 ratings