問題描述
我對所有 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
- Chrome 支持表
- 節點支持表
這篇關于為什么在 Electron 項目中需要 Babel的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!