問題描述
我對所有 Javascript 生態(tài)系統(tǒng)都感到很困惑.我正在嘗試 Electron,這似乎是一種很有前途的創(chuàng)建跨平臺應(yīng)用程序的方法,它利用了節(jié)點(diǎn)和 Chrome 的強(qiáng)大功能.我創(chuàng)建了一個小應(yīng)用程序并使用了一些現(xiàn)代"(這讓 C# 程序員發(fā)笑)javascript 概念作為 lambda,并且它開箱即用(我認(rèn)為這很自然,因?yàn)槲矣凶钚掳姹镜墓?jié)點(diǎn)).然后我嘗試下一步,我在使用 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 在一個最新的、預(yù)先知道的、具有最新節(jié)點(diǎn)和 chrome 的環(huán)境中工作,并且如果我將它捆綁在一個應(yīng)用程序中,為什么我不應(yīng)該直接在 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 中達(dá)到 ES7 的功能,你就不需要 Babel.您有兩個進(jìn)程正在進(jìn)行主進(jìn)程和渲染進(jìn)程.
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.
主進(jìn)程:
- 使用節(jié)點(diǎn)(electron v1.7.x 上的當(dāng)前節(jié)點(diǎn)版本 v7.9.0)
- 以 99% 的覆蓋率支持 ES6/ES7,但以下情況除外:
- RegExp.prototype.compile 不返回這個
- Symbol.toStringTag 不會影響現(xiàn)有的內(nèi)置函數(shù)
- Array.prototype.values(反正沒人支持)
渲染過程:
- 使用 Chromium(當(dāng)前 Chromium 版本為 58)
- 支持 ES6 99% 和 ES7 覆蓋率約為 85%,您可以通過
new BrowserWindow({ webPreferences: { experimentalFeatures: true } })
啟用 experimatal features 標(biāo)志來增加支持.李>
- 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 用于開發(fā)的相同版本的節(jié)點(diǎn),這將防止不兼容問題.您可以通過查看電子存儲庫中的
.node-version
文件來檢查這一點(diǎn).在當(dāng)前版本中,這將是 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.如果你想使用更新的函數(shù),使用 BableJs 仍然是有效的一些操作符,比如擴(kuò)展操作符
...
幾乎我所有的項(xiàng)目仍然使用帶有Stage 0"預(yù)設(shè)的 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 規(guī)范和方法的一些很好的列表
Some good lists for checking the supported ES spec and methods
- Chrome 支持表
- 節(jié)點(diǎn)支持表
這篇關(guān)于為什么在 Electron 項(xiàng)目中需要 Babel的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!