要在 Linux 上运行 Electron 的构建,可以按照以下步骤进行操作:
node -v
npm -v
npm init
npm install --save-dev electron
main.js
的文件,该文件将是你的 Electron 应用的入口点。在 main.js
文件中,添加以下代码:const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
index.html
的文件,该文件将是你的 Electron 应用的界面。在 index.html
文件中,添加以下代码:
Hello World!
Hello World!
package.json
文件中添加一个新的脚本,用于启动 Electron 应用。将以下代码添加到 scripts
部分:"start": "electron ."
npm start
这样,你的 Electron 应用就会运行起来,并显示一个包含 "Hello World!" 的窗口。
请注意,上述代码示例仅作为基本的起点,你可以根据自己的需求进行修改和扩展。你可以使用 Electron 提供的各种 API 来创建更复杂的应用程序。