为什么在电子项目中需要Babel [英] Why is Babel needed in an Electron project

查看:64
本文介绍了为什么在电子项目中需要Babel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对所有Javascript生态系统都很困惑.我正在尝试使用Electron,这似乎是利用节点和Chrome的强大功能来创建跨平台应用程序的一种有前途的方法.我创建了一个小应用程序,并使用了一些现代"(使C#程序员大笑)的javascript概念作为lambda,并且它开箱即用(我认为这很自然,因为我使用的是最新版本的node).然后,我尝试下一步,在示例中使用Babel看到了很多样板.

I'm quite confused about all the Javascript ecosystem. I'm trying Electron that seems a promising way in creating cross platform apps, leveraging the power of node and Chrome. I create a small app and used some "modern" ( this make a C# programmer laughing ) javascript concepts as lambdas, and it worked out of the box ( I supposed it was natural, since I've the latest version of node ). Then I'm trying to move next, and I see a lot of boilerplating in the examples using for example Babel.

我为什么需要这个?

如果电子工作在最新的,事先已知的节点和铬环境中,并且如果我将其捆绑在单个应用程序中,为什么我不应该直接在ESwhatever中直接编码?

If electron works in a up-to date, known in advance, environment with node and chrome up to date, and if I bundle this in a single app, why shouldn't I simply code directly in ESwhatever?

推荐答案

如果您只需要电子中达到ES7的功能,则不需要Babel.您在主流程和渲染流程上有两个流程.

You don't need Babel if you only want features up to ES7 in electron. You have two processes going on the main process and the render process.

主要过程:

  • 使用节点(电子v1.7.x上的当前节点版本v7.9.0)
  • 以99%的覆盖率支持ES6/ES7,但以下情况除外:
    • RegExp.prototype.compile不返回此值
    • Symbol.toStringTag不会影响现有的内置
    • Array.prototype.values(反正没人支持)
    • Uses node (Current node version v7.9.0 on electron v1.7.x)
    • Support ES6/ES7 with 99% coverage, the exceptions are:
      • RegExp.prototype.compile does not return this
      • Symbol.toStringTag does not affect existing built-ins
      • Array.prototype.values (No one supports this anyway)

      渲染过程:

      • 使用铬(当前的铬版本为58)
      • 通过约85%的覆盖率支持ES6 99%和ES7,您可以通过new BrowserWindow({ webPreferences: { experimentalFeatures: true } })启用实验性功能标志来增加支持.
      • Uses chromium (Current chromium version is 58)
      • Supports ES6 99% and ES7 with ~85% coverage, you can increase the support by enabling the experimatal features flag via new BrowserWindow({ webPreferences: { experimentalFeatures: true } }).

      请注意,我鼓励您使用电子用于开发的相同版本的节点,这样可以防止不兼容的问题.您可以通过查看电子存储库中的.node-version文件来进行检查.在当前版本中,该版本为v7.9.0.

      Be aware that I would encourage you to use the same version of node that electron uses for development, it will prevent incompatibility issues. you can check this by viewing the .node-version file in the electron repository. At the current version this would be v7.9.0.

      如果您想使用甚至更新的功能,仍然有使用BableJ的要点,因为某些原因,例如散布运算符...,由于这个原因,几乎我所有的项目仍然使用babel,并且预设了阶段0".

      There are still valid points to use BableJs if you want to use even newer functions some operators like the spread operator ... nearly all of my projects still use babel with the 'Stage 0' preset for that reason.

      一些不错的清单,用于检查受支持的ES规范和方法

      Some good lists for checking the supported ES spec and methods

      • Chrome support table
      • Node support table

      这篇关于为什么在电子项目中需要Babel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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