我有一个用React创建的web应用程序。我想创建该应用程序的桌面版本。为此,我在public文件夹中添加了electron.js文件。在electron.js文件中是基本的电子代码,它获取index.html并将其转换为桌面应用程序,如下所示:
const { app, BrowserWindow } = require('electron')
const path = require("path");
const isDev = require("electron-is-dev");
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
win.loadURL(isDev ? "http://localhost:3000" : `file://${path.join(__dirname, "../build/index.html")}`);
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})该应用程序是工作的,我没有添加任何电子代码到src文件夹。如何在我的React-Electron代码中获得Windows、Mac和Linux的可执行文件?我的机器是在linux上运行的
发布于 2020-12-29 19:39:26
您可以使用一个名为electron-builder的库。
使用npm Install或yarn add安装库,然后在package.json中添加一个新任务来运行electron-builder例如,在windows、linux和mac上构建一个你可以运行的应用程序,这些都可以放在package.json中,这样你就不需要在每次构建时都输入它。也可以使用编程API构建应用程序。您可以在文档中找到更多详细信息,还有tutorials和guides。
electron-builder -mwl
https://stackoverflow.com/questions/65491316
复制相似问题