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

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

问题描述

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

我为什么需要这个?

如果 electron 在一个最新的、预先知道的、具有最新节点和 chrome 的环境中工作,并且如果我将它捆绑在一个应用程序中,为什么我不应该直接在 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?

推荐答案

如果你只想要在 electron 中达到 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.

主进程:

  • 使用节点(electron v1.7.x 上的当前节点版本 v7.9.0)
  • 以 99% 的覆盖率支持 ES6/ES7,但以下情况除外:
    • RegExp.prototype.compile 不返回这个
    • Symbol.toStringTag 不会影响现有的内置函数
    • Array.prototype.values(反正没人支持)

    渲染过程:

    • 使用 Chromium(当前 Chromium 版本为 58)
    • 支持 ES6 99% 和 ES7 覆盖率约为 85%,您可以通过 new BrowserWindow({ webPreferences: { experimentalFeatures: true } }) 启用 experimatal features 标志来增加支持.李>
    • 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 } }).

    请注意,我鼓励您使用与 electron 用于开发的相同版本的节点,这将防止不兼容问题.您可以通过查看电子存储库中的 .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.

    如果你想使用更新的函数,使用 BableJs 仍然是有效的一些操作符,比如扩展操作符 ... 几乎我所有的项目仍然使用带有Stage 0"预设的 babel出于这个原因.

    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

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

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