問題描述
在一篇博文中,作者提到 Electron 將 Node 和 Chromium 組合成一個單一的context" 這意味著我們不必使用 Browserify 來轉(zhuǎn)換代碼.
In a blog post the author mentions that Electron combines Node and Chromium into a "single context" which implies that we don't have to use Browserify to transform code.
我知道 Electron 的一個含義是您可以使用 Web 技術(shù)構(gòu)建跨平臺的桌面應(yīng)用程序.我也理解我們能夠?qū)懭胛募到y(tǒng)的原因是因為 Electron 已經(jīng)嵌入了 Node.此外,我們能夠使用 HTML/CSS/JS/DevTools 的原因是因為 Chromium 被嵌入了.但是,我不要以為作者在說這個.
I understand that one implication of Electron is you can build cross-platform desktop apps using web technologies. I also understand the reason why we're able to write to the filesystem is because Electron has Node baked in. Also, the reason we're able to use HTML/CSS/JS/DevTools is because Chromium is baked in. However, I don't think this is what the author is talking about.
- Electron 如何將 Node 和 Chromium 組合成一個單一上下文"?
- 為什么不再需要使用 Browserify?
推薦答案
Chromium 是一個基于 Webkit 的 Web 瀏覽器,帶有 V8 javascript 引擎.它支持所有常用的瀏覽器和 DOM API,因此適合制作網(wǎng)頁,但不擅長與底層系統(tǒng)交互.
Chromium is a Webkit based web browser with the V8 javascript engine. It supports all the usual browser and DOM APIs and thus is good for making web pages and not good at interacting with the underlying system.
Node.js 是通過剝離 V8 引擎、制作無頭命令行應(yīng)用程序并添加廣泛的 API 來訪問文件系統(tǒng)而構(gòu)建的,require()
其他文件、運行其他 shell 程序等(您對真正的腳本語言的期望.
Node.js was built by striping out the V8 engine, making a headless command line application, and adding extensive APIs to access the file system, require()
other files, run other shell programs, etc. (things you'd expect of a true scripting language.
Electron 以一種簡化的方式嘗試將 Chromium 中使用的 V8 引擎替換為新的更通用的 Node.js 引擎.它向 node.js 公開了一些額外的 API 以允許打開 chromium 窗口,但也允許使用 <script>
的每個 chromium 窗口標(biāo)記將使用 node.js 引擎對其進行解釋.
Electron in a simplified way is an attempt to replace the V8 engine used in Chromium with the new more general purpose oriented one of Node.js. It exposes a few extra APIs to node.js to allow for opening chromium windows, but also every chromium window using a <script>
tag will interpret it with the node.js engine.
為什么選擇 Electron? Chromium 不能自己做到這一點的原因是因為它最初被設(shè)計為一個網(wǎng)絡(luò)瀏覽器,而在網(wǎng)絡(luò)瀏覽器中,文件系統(tǒng) API 將是聞所未聞的,因為通常文件是托管在遠程服務(wù)器上并訪問用戶計算機上的文件會帶來安全風(fēng)險(因為為什么任何單個網(wǎng)頁都可以訪問您的所有文件?).
Why Electron? The reason that Chromium can't do this by itself is because it was originally designed to be a web browser and in web browsers file system APIs would be unheard of as typically files are hosted on a remote server and accessing files on a user's computer would be a security risk (because why should any single webpage have access to all your files?).
require
語句現(xiàn)在可以開箱即用,因為 node.js 具有文件系統(tǒng)支持將允許它們從磁盤同步讀取,而無需將它們捆綁到同一個 javascript 文件或從服務(wù)器.
require
statements now work out of the box because node.js has filesystem support will allows them to be synchronously read from the disk without the need for bundling them into the same javascript file or requesting them from a server.
這篇關(guān)于Electron 將 Node.js 和 Chromium 上下文結(jié)合起來意味著什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!