2

I have a web app created with React. I want to create the desktop version of that app. To do that, i added electron.js file in the public folder. Inside the electron.js file is the basic electron code that take index.html and turn it to a desktop app that looked like this:

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()
    }
})

The app is works and I don't add any electron code to the src folder. How can i get the executable for Windows, Mac, and Linux in my React-Electron code? My machine run on linux

1
  • Read here electron.build Windows/Mac/Linux Commented Dec 29, 2020 at 11:26

1 Answer 1

2

You could use a library called 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 you don't need to type it everytime you want to build. It's also possible to build an app using a programmatic API. You'll find more details in the docs, there are also tutorials and guides.

electron-builder -mwl

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.