Electron5.x 之前默认可以在主进程以及渲染进程中直接使用 nodejs, 但是在 Electron5.x 默认没法在渲染进程中直接使用 nodejs,如果我们想在渲染进程中使用 nodejs 的话需要进 行如下配置。
const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences : {
// 开启渲染基进程中使用nodejs
nodeIntegration : true,
contextIsolation: false
}
});
两个都要配置