如何在浏览器中使用Babel 6外部助手? [英] How to use Babel 6 external helpers in the browser?

查看:105
本文介绍了如何在浏览器中使用Babel 6外部助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先是问题:

我在哪里可以找到external-helpers.js脚本,或者如何为Babel 6构建外部助手?

在Babel 5.x中,我能够使用 externalHelpers 选项,其中包括 external-helpers.js ,曾经是babel-core软件包。转到Babel 6,我看到外部助手现在正在外部助手-2 插件。这可以在我的转换代码中包含相关的 babelHelper 调用,但就是这样;我需要实际的帮助定义!

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!

在问题中 external-helpers.js 添加缺少的构建脚本,建议使用CLI自行构建。我没有看到任何似乎与构建外部助手有关的CLI选项。

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.

推荐答案

我设法构建<$ c使用 babel-core external-helpers.js >包和节点REPL:

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());

我想,根据你的情况,你也可以通过构建脚本构建外部帮助文件( Grunt,Gulp等。)

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

这篇关于如何在浏览器中使用Babel 6外部助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆