簡體   English   中英

如何從 React-Electron 項目創建可執行文件

[英]How to create an executable file from React-Electron project

我有一個用 React 創建的 web 應用程序。 我想創建該應用程序的桌面版本。 為此,我在public文件夾中添加了electron.js文件。 electron.js文件中是基本的 electron 代碼,它采用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()
    }
})

該應用程序有效,我沒有將任何 electron 代碼添加到src文件夾。 如何在我的 React-Electron 代碼中獲取 Windows、Mac 和 Linux 的可執行文件? 我的機器在 linux 上運行

您可以使用一個名為electron-builder的庫。

Install the library with npm install or yarn add then add a new task to package.json to run electron-builder for example to build an app to windows, linux and mac you can run, these can be put in package.json as well so您無需在每次構建時都鍵入它。 也可以使用編程 API 構建應用程序。 您將在文檔中找到更多詳細信息,還有教程指南

electron-builder -mwl

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM