electron热更新_如何在Electron上设置热重装

electron热更新

When working on an Electron app, it’s very handy to set up hot reload, so that the application updates without having to restart it.

在Electron应用程序上工作时,设置热重装非常方便,这样应用程序无需重启就可以更新。

You can do that using the npm module electron-reloader.

您可以使用npm模块electronic-reloader做到这一点

Suppose you have this sample Electron application:

假设您有以下电子示例应用程序:

index.js

index.js

const { app, BrowserWindow } = require('electron')

function createWindow() {
  // Create the browser window.
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
    },
  })

  // and load the index.html of the app.
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

index.html

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World!</title>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

Install electron-reloader as a development dependency:

安装electron-reloader作为开发依赖项:

npm install -D electron-reloader

Then add this line to the index.js file:

然后将此行添加到index.js文件:

try {
  require('electron-reloader')(module)
} catch (_) {}

and that’s it! Now when you start the application using electron ., or npm start if you have

就是这样! 现在,当您使用electron .启动应用程序时electron .npm start如果有)

"start": "electron .",

in your package.json, any change you apply to the application files will be reflected in the application window.

package.json ,您对应用程序文件所做的任何更改都会反映在应用程序窗口中。

翻译自: https://flaviocopes.com/electron-hot-reload/

electron热更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值