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

Add docs for @babel/register/experimental-worker #2616

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/register.md
Expand Up @@ -143,4 +143,15 @@ Because it is your own code that triggered the load, and not the logic within
`@babel/register` itself, this should successfully compile any plugin/preset
that loads synchronously.

## Experimental Babel 8 implementation

You can also test the new experimental implementation that will be enabled by default in Babel 8, using
```js
require("@babel/register/experimental-worker");
```

It internally runs Babel asynchronously, so it's compatible with [`.mjs` configuration files](https://babeljs.io/docs/en/config-files#configuration-file-types). You can already use it as a replacement of `@babel/register` with a few caveats:
nicolo-ribaudo marked this conversation as resolved.
Show resolved Hide resolved
- If you programmatically specify `@babel/register` options (using `require("@babel/register")({ /* ... options */ })`), you must make sure that they are serializable. This means that you cannot pass plugin functions defined inline, but you must move them to a separate `./my-plugin.js` file or to a `babel.config.js` file.
- The new implementation is still experimental: it _should_ have the same features as the existing one, but there may be some new bugs and regressions.

**Note:** `@babel/register` does _not_ support compiling native Node.js ES modules on the fly, since currently there is no stable API for intercepting ES modules loading.