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

javascript - Why is Babel needed in an Electron project - Stack Overflow

programmeradmin1浏览0评论

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.

Why do i need this?

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?

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.

Why do i need this?

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?

Share Improve this question asked Nov 4, 2017 at 7:41 Felice PollanoFelice Pollano 33.3k10 gold badges77 silver badges121 bronze badges 4
  • 1 Because that environment supports only ES-somethingelse? Or you want to try out some new experimental syntactic features that are not yet available natively? Or you even want to use your own customisations? – Bergi Commented Nov 4, 2017 at 9:23
  • @Bergi not so easy to understand what's supported and not, – Felice Pollano Commented Nov 4, 2017 at 10:06
  • Most probably the examples you are referring to date from the time Electron was using a Chrome version that did not support yet this ES syntax. – ghybs Commented Nov 4, 2017 at 10:36
  • @FelicePollano "I create a small app and used some "modern" ( this make a C# programmer laughing ) javascript concepts as lambdas..." JavaScript had lambdas way before C# (C# 3.0 added this in 2007) and also JavaScript has a lot of modern features regardless if the language can be a bit inconsistent – VladNeacsu Commented Apr 4, 2019 at 11:26
Add a ment  | 

1 Answer 1

Reset to default 10

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.

Main Process:

  • Uses node (Current node version v7.9.0 on electron v1.7.x)
  • Support ES6/ES7 with 99% coverage, the exceptions are:
    • RegExp.prototype.pile does not return this
    • Symbol.toStringTag does not affect existing built-ins
    • Array.prototype.values (No one supports this anyway)

Render process:

  • 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 } }).

Be aware that I would encourage you to use the same version of node that electron uses for development, it will prevent inpatibility 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.

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.

Some good lists for checking the supported ES spec and methods

  • Chrome support table
  • Node support table
发布评论

评论列表(0)

  1. 暂无评论