【Electron】是否在 Electron 中运行
4月7日 / 4月7日
简介
在 Electron 里,nodeIntegration 这个属性控制着渲染进程能否使用 Node.js 的 API。当 nodeIntegration 设置为 true 时,渲染进程会和 Node.js 环境集成,这意味着在渲染进程的全局 window 对象上会暴露 Node.js 的全局变量和 API,其中就包括 process 对象。所以,开启 nodeIntegration 之后,可以通过 window.process 访问到 Node.js 的 process 对象。
检测
1if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) { 2 return true; 3}
cd ..