How to use additional Babel 6 helpers in a browser?

First question:

Where can I find external-helpers.js script, or how can I build external helpers for Babel 6?

In Babel 5.x, I was able to use the externalHelpers parameter, which should include external-helpers.js , which was used in the babel-core package. Turning to Babel 6, I see that external helpers are now an external-helpers-2 plugin. This includes including the appropriate babelHelper calls in my converted code, but that is it; I need the actual definitions of helpers!

In the release, add the missing script construct for external-helpers.js , suggesting "create it yourself using the CLI". I do not see any CLI parameters that seem to be involved in creating external helpers.

+5
source share
2 answers

I managed to create external-helpers.js with the babel-core package and Node REPL:

 var helperBuilder = require('./lib/tools/build-external-helpers'); fs.writeFileSync('external-helpers.js', helperBuilder()); 

I suggest that depending on your situation, you can also create an external helpers file by building a script (Grunt, Gulp, etc.)

+4
source

The CLI command mentioned in the issue you mention is babel-external-helpers , which is part of the babel-cli npm package. If babel-cli installed, running babel-external-helpers --help gives the following output:

 Usage: babel-external-helpers [options] Options: -h, --help output usage information -l, --whitelist [whitelist] Whitelist of helpers to ONLY include -t, --output-type [type] Type of output (global|umd|var) 

It simply outputs the file to stdout, so to print the code into a file, you do babel-external-helpers [options] > babel-helpers.js .

+2
source

Source: https://habr.com/ru/post/1235936/


All Articles