the renderer has no direct access to require or other Node.js APIs. In order to directly include NPM modules in the renderer, you must use the same bundler toolchains (for example, webpack or parcel) that you use on the web.
翻译:
Electron 渲染器无权直接访问 require 或其他 Node.js API。 为了在渲染器中直接包含 NPM 模块,您必须使用与在 web 开发时相同的打包工具 (例如 webpack 或 parcel)
请问下:
1.渲染器是否可以直接访问Electron API?
2.使用打包工具就可以直接访问nodeJS API的原理是什么?在web开发中也是使用了之后就可以直接访问nodeJS API吗?
3.可以用vite吗?
Electron 用的 Chromium (Chrome 浏览器内核) 渲染,渲染进程的执行环境本身都是受限于上层。
Chrome 浏览器中并没有捆绑 NodeJS 所以当然无法在其渲染进程中使用 NodeJS 。
Electron APP 主进程其实使用的 NodeJS 不过为了保持和浏览器渲染一致并没有魔改渲染进程。