最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use Babel 6 external helpers in the browser? - Stack Overflow

programmeradmin0浏览0评论

First the question:

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

In Babel 5.x, I was able to use the externalHelpers option, which required including external-helpers.js, which used to be in the babel-core package. Moving on to Babel 6, I see that external-helpers is now external-helpers-2 plugin. This does the job of including the relevant babelHelper calls in my transpiled code, but that is it; I need the actual helper definitions!

In the issue add missing build script for external-helpers.js, it is suggested to " build it yourself with the CLI". I don't see any CLI options that seem to deal with building external helpers.

First the question:

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

In Babel 5.x, I was able to use the externalHelpers option, which required including external-helpers.js, which used to be in the babel-core package. Moving on to Babel 6, I see that external-helpers is now external-helpers-2 plugin. This does the job of including the relevant babelHelper calls in my transpiled code, but that is it; I need the actual helper definitions!

In the issue add missing build script for external-helpers.js, it is suggested to " build it yourself with the CLI". I don't see any CLI options that seem to deal with building external helpers.

Share Improve this question edited Nov 15, 2015 at 8:36 Felix Kling 817k181 gold badges1.1k silver badges1.2k bronze badges asked Nov 14, 2015 at 0:45 LokuaLokua 5766 silver badges15 bronze badges 2
  • Please read tag descriptions. babel is for questions for a Python library with said name. – Felix Kling Commented Nov 15, 2015 at 8:36
  • Doh! Thanks, @FelixKling. – Lokua Commented Nov 15, 2015 at 9:52
Add a ment  | 

2 Answers 2

Reset to default 4

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

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

I imagine that, depending on your situation, you could also build the external helpers file by build script (Grunt, Gulp, etc.)

The CLI mand referred to in the issue you mention is babel-external-helpers, which is part of the babel-cli npm package. With the babel-cli package installed, running babel-external-helpers --help gives the following self-explanatory 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 to a file, you do babel-external-helpers [options] > babel-helpers.js.

发布评论

评论列表(0)

  1. 暂无评论