const {app, BrowserWindow} = require('electron') const path = require('path') let mainWindow function createWindow () { console.log(123) mainWindow = new BrowserWindow({ width: 900, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration: true // Set this to use nodejs }, frame:true }) mainWindow.loadFile('main.html') mainWindow.on('closed', function () { mainWindow = null }) } app.on('ready', createWindow) app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit() }) app.on('activate', function () { if (mainWindow === null) createWindow() })
The first grant of Bo:
CreateWindow function provided in the first rendering process mainWindow there is a webpreferences, the first argument which is not yet know, maybe subsequent updates. The second argument is that if the current process html files used by the need to use nodejs module you must add this parameter, and is set to true, otherwise nodejs statement all target html file will fail