capacitor-community / electron

Deploy your Capacitor apps to Linux, Mac, and Windows desktops, with the Electron platform! 🖥️
https://capacitor-community.github.io/electron/
MIT License
318 stars 58 forks source link

how do i use/build this? #292

Open laurencefass opened 1 week ago

laurencefass commented 1 week ago

Your docs say:

Build your webapp in your capacitor initiated project ('npm run build' for example).
Run npm i @capacitor-community/electron in your webapp project directory. This will install the platform for use with the @capacitor/cli.
Run npx cap add @capacitor-community/electron to initiate the platform, this will create the electron folder in your webapp project.
Run npx cap open @capacitor-community/electron to start your app in electron.

I dont just want to install it I want to create an image but there is no advice how to do any of it in the docs.

I asked the AI it came up with this. I have no idea how accurate it is, so Im hoping this could serve as the basis for future documentation:

My question:

ive added electron to my capacitor project. how do i sync it? how do i run it on windows?

AI:


Step-by-Step Guide
Install Electron and Build Tools

Ensure you have the necessary tools installed on your VPS.

sh
Copy code
npm install --save @capacitor-community/electron
Add Electron Platform

Add Electron as a platform in your Capacitor project.

sh
Copy code
npx cap add @capacitor-community/electron
Sync Your Project

Sync the project to ensure that the Electron platform is correctly set up.

sh
Copy code
npx cap sync @capacitor-community/electron
Build Web Assets

Build your web assets.

sh
Copy code
npm run build
Build Electron App

Navigate to the Electron directory and build the Electron app for Windows.

sh
Copy code
cd electron
npm install
npm run build
Package the Electron App

Use Electron Packager or Electron Builder to create a distributable package.

Using Electron Packager:

sh
Copy code
npm install electron-packager --save-dev
npx electron-packager . --platform=win32 --arch=x64 --out=dist --overwrite
Using Electron Builder:

First, install Electron Builder:

sh
Copy code
npm install electron-builder --save-dev
Then, add a build script to your package.json:

json
Copy code
"scripts": {
  "build": "next build",
  "start": "next start",
  "electron:build": "electron-builder"
}
And create an Electron Builder configuration in package.json:

json
Copy code
"build": {
  "appId": "com.yourapp.id",
  "productName": "YourAppName",
  "directories": {
    "output": "dist"
  },
  "files": [
    "build/**/*",
    "main.js"
  ],
  "win": {
    "target": "nsis"
  }
}
Now, run the build script:

sh
Copy code
npm run electron:build
Transfer the Executable to Windows

Once the build is complete, the executable will be in the dist directory. Transfer this file to your Windows machine using SCP, FTP, or any other file transfer method.

Using SCP:

sh
Copy code
scp user@your_vps:/path/to/your/project/electron/dist/YourAppName-Setup.exe C:\path\to\your\local\machine\
Run the Executable on Windows

After transferring the executable, navigate to its location on your Windows machine and run it.

Example Commands
Build the Electron App:

sh
Copy code
cd electron
npm install
npm run build
Package the Electron App (with Electron Packager):

sh
Copy code
npx electron-packager . --platform=win32 --arch=x64 --out=dist --overwrite
Package the Electron App (with Electron Builder):

sh
Copy code
npm run electron:build
Transfer the Executable:

sh
Copy code
scp user@your_vps:/path/to/your/project/electron/dist/YourAppName-Setup.exe C:\path\to\your\local\machine\
By following these steps, you can build your Electron app on your VPS, transfer the executable to your Windows machine, and run it locally. This approach allows you to develop and package your app in a headless environment and then test and run it on your local machine.