Skip to content

Commit

Permalink
Add docs for @babel/register/experimental-worker (#2616)
Browse files Browse the repository at this point in the history
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
  • Loading branch information
nicolo-ribaudo and JLHwung committed Feb 2, 2022
1 parent cfc7b59 commit f7a31ad
Showing 1 changed file with 11 additions and 0 deletions.
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](config-files.md#configuration-file-types). You can already use it as a replacement of `@babel/register` with a few caveats:
- 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.

0 comments on commit f7a31ad

Please sign in to comment.