让ES6在WebStorm中工作 [英] Getting ES6 to work in WebStorm

查看:101
本文介绍了让ES6在WebStorm中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关如何在WebStorm 10上使用ES6的任何想法?

Any ideas on how to use ES6 on WebStorm 10?

以下是我到目前为止所做的事情:

Here's what I have done so far:


  1. 已安装的Babel。

  2. 使用设置>工具>文件监视器激活Babel。选中Babel复选框。

  3. 编辑配置>在启动文件观察器之前> +然后'运行文件监视器'。

  4. 将代码设置为ES6

  5. 更改了我的运行配置以使用已编译的版本。

  1. Installed Babel.
  2. Activated Babel with Settings > Tools > File watchers. checked Babel checkbox.
  3. Edit configurations > Before launch file watchers > + then 'Run File Watchers".
  4. Set code as ES6
  5. Changed my run configuration to use the compiled version.

然后创建了以下一小段代码:

Then created the following trivial piece of code:

require("babel/register");
function* count(n){
    console.log(n);
}

此代码显示没有语法错误,应该如此。(方便确保ES6打开的方法。

This code shows up with no syntax errors, as it should. (A convenient way to make sure ES6 is turned on).

运行它(实际运行编译版本),然后得到它....

Run it (run the compiled version, actually), and get this ....

var marked0$0 = [count].map(regeneratorRuntime.mark);
                            ^
ReferenceError: regeneratorRuntime is not defined

为什么?如何使用Babel进行预编译然后运行?是不是应该采用再生器照顾这一行:

Why? How do I get it to precompile with Babel and then run? Isn't the regenerator supposed to be taken care of with this line:

require("babel/register");

(Windows 7,如果这很重要)。

(Windows 7, if that is important).

推荐答案

我认为根据您所描述的错误的性质,您可能需要做两件事才能使其正常工作。

I think there are two things you probably need to do to make it work based on the nature of the error you're describing.


  1. npm install babel-core

  2. add - -optional runtime 作为调用babel的参数

  1. npm install babel-core
  2. add --optional runtime as an argument to the invocation of babel

这是基于详细描述的内容此处

This is based on what's described in some detail here.

这篇关于让ES6在WebStorm中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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