Skip to content
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

Publish JS modules build to npm #8246

Closed
justinfagnani opened this issue Jul 1, 2018 · 6 comments
Closed

Publish JS modules build to npm #8246

justinfagnani opened this issue Jul 1, 2018 · 6 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@justinfagnani
Copy link
Contributor

Feature Request

Is your feature request related to a problem? Please describe.

I'd like to load Babel in a browser using the native module system that all browsers now support. Babel seems to be only distributed as CJS though.

Describe the solution you'd like

Publish standard JS modules, probably to a separate modules/ folder of the packages, along with a module field in package.json pointing to modules/index.js

Describe alternatives you've considered

There is no good solution for importing CJS into native modules. CJS can be build and bundled into script that's executable by browsers, but the semantics are different enough from standard JS modules that it isn't possible to reliably reconstruct the named exports of the original source. Since Babel is written as JS modules, hopefully the Flow compiler can simply strip out the non-standard syntax and output pure modules.

Teachability, Documentation, Adoption, Migration Strategy

Modules are standardized and supported in all current browsers. They are supported in node.js via the esm loader.

Loading Babel in browsers without any build system, and importantly being compatible with libraries and applications trying to use only pure modules, would be a big win for Babel 7.

@babel-bot
Copy link
Collaborator

Hey @justinfagnani! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

Even if we published Babel without transpiling modules, it would still rely on node semantics to esolve dependencies (e.g. import "@babel/types" -> ../somewhere_up_in_the_directories_chain/node_modules/@babel/types).

@justinfagnani
Copy link
Contributor Author

That's ok, many tools like unpkg.com with the ?module query param, or the Polymer build system support rewriting just the import specifiers.

For future native support, there's the package-name-maps proposal which will let browsers use named imports.

@loganfsmyth
Copy link
Member

Loading Babel in browsers without any build system, and importantly being compatible with libraries and applications trying to use only pure modules, would be a big win for Babel 7.

Babel's standard workflow is specifically Node >= LTS, so if browser usage of this is the primary driver, I suppose we could consider an ESM build of @babel/standalone.

@laquereric
Copy link

I agrre that 'in-browser' application would be a 'big win'. I am investigating another application scenario as well where Node would NOT be in the picture. An 'ESM build of @babel/standalone' would be great. I would be glad to help if I can.

@nicolo-ribaudo
Copy link
Member

Also tracked by #11701. We'll do this in Babel 8.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants