文檔知識點
https://electronjs.org/docs/tutorial/about
(1)Electron通過將Chromium和Node.js合並到同一個運行時環境中,並將其打包為Mac,Windows和Linux系統下的應用來實現這一目的。
即electron內置了瀏覽器和node環境。
Electron包括2個進程:main-process ,render-process。
main-process:控制應用的生命周期
render-process:瀏覽器渲染。
這2個進行之間通過IPC進行通信。
(2) 通信過程待研究
https://electronjs.org/docs/faq#how-to-share-data-between-web-pages
開發小tips
(1)main 進程熱更新
webpack配置:
function startMain () { return new Promise((resolve, reject) => { mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main) const compiler = webpack(mainConfig) compiler.plugin('watch-run', (compilation, done) => { logStats('Main', chalk.white.bold('compiling...')) hotMiddleware.publish({ action: 'compiling' }) done() }) compiler.watch({}, (err, stats) => { if (err) { console.log(err) return } logStats('Main', stats) if (electronProcess && electronProcess.kill) { manualRestart = true process.kill(electronProcess.pid) electronProcess = null startElectron() setTimeout(() => { manualRestart = false }, 5000) } resolve() }) }) }
main進程的熱更新使用的webpack的watch-run插件,所以main進程修改后會熱更新。render進程熱更新大家很熟悉了。
(2)main進程log記錄
electron-log 插件可以打印main主進程信息。
https://github.com/megahertz/electron-log
需要說明的事:默認只有error信息可以打印到文件中。
app.get('/situation/open/getJsonFiles', (req, res) => { // 默認情況下只打印error信息,所以使用log.error打印所需的信息即可
log.error('Hello, log2') readJsonFiles(app).then(ele => { res.send(ele) }).catch(err => { res.send(err, '---ree') }) })
持續更新