乐闻世界logo
搜索文章和话题

How To Compile An Electron Application To .exe file

1个答案

1

Packaging an Electron application as an .exe file for Windows is a common requirement. To achieve this, popular packaging tools such as electron-packager or electron-builder are commonly used. Below are the steps to use these tools to package an Electron project into an .exe file:

Using electron-packager

  1. Install electron-packager If not already installed, you can install it via npm. Open your project directory in the terminal and run the following command:

    bash
    npm install electron-packager --save-dev
  2. Configure the packaging command In the project's package.json file, you can add a script to run electron-packager. For example:

    json
    "scripts": { "package-win": "electron-packager . MyApp --platform=win32 --arch=x64 --out=dist/" }
  3. Run the packaging command Execute the following command in the terminal to generate the .exe file:

    bash
    npm run package-win

    This will generate a Windows application in the dist/ directory, including MyApp.exe.

Using electron-builder

  1. Install electron-builder Install electron-builder via npm:

    bash
    npm install electron-builder --save-dev
  2. Configure electron-builder Set up electron-builder options in package.json. For example:

    json
    "build": { "appId": "your.app.id", "win": { "target": "nsis", "icon": "build/icon.ico" } }
  3. Add the build script Include the following in the scripts section of package.json:

    json
    "dist": "electron-builder --win"
  4. Execute the build command Run the following command to generate the installer:

    bash
    npm run dist

    This will produce an NSIS installer in the dist folder under your project directory.

Summary

Both electron-packager and electron-builder can effectively package an Electron project into Windows executables. The choice depends on your specific needs; for more complex installation requirements (such as custom installation steps or auto-updates), electron-builder is a better choice. Each tool offers detailed documentation and community support, enabling you to select based on your project requirements.

2024年6月29日 12:07 回复

你的答案