Electronアプリのパッケージ化
`electron-builder`などのツールを使い、さまざまなOS(Windows、macOS、Linux)向けにElectronアプリケーションを配布用パッケージにする方法を学びます。
「Electronアプリのパッケージ化」はCoddyKit上の無料Electron Desktop App Developmentレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはElectron Desktop App Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Electron Desktop App Developmentコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Package Your App?
When you develop an Electron app, it runs using Node.js and Chromium. However, your users won't have Node.js installed or know how to run your development files.
Packaging your application means bundling all its necessary files—your code, Electron runtime, and any assets—into a single, easy-to-distribute executable file or installer, like a .exe for Windows or a .dmg for macOS.
Meet Electron Builder
electron-builder is the most popular and robust solution for packaging and distributing Electron applications. It simplifies the complex process of preparing your app for various operating systems.
- Cross-Platform: Build for Windows, macOS, and Linux from a single codebase.
- Installers: Generate platform-specific installers (e.g., NSIS for Windows, DMG for macOS).
- Auto-Updates: Integrates seamlessly with auto-update mechanisms.
- Customization: Offers extensive options for icons, product names, and more.
Installing Electron Builder
First, you need to add electron-builder as a development dependency to your project. Open your terminal in your project's root directory and run:
npm install --save-dev electron-builderBasic Project Setup
Before packaging, ensure your package.json is correctly set up. It defines your application's basic information and entry point. Here's a minimal example:
name: Your app's unique identifier.version: Current version.main: Path to your main Electron script.scripts.start: Command to run your app in development.
{
"name": "my-electron-app",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ."
}
}Configure package.json for Build
Now, let's add the build configuration to your package.json. This block tells electron-builder how to package your app.
appId: A unique identifier for your app (e.g.,com.yourcompany.yourapp).productName: The name users will see for your app.directories.output: Where the packaged files will be saved (commonlydist).scripts.build: The command to trigger the build.
{
"name": "my-electron-app",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "electron-builder"
},
"build": {
"appId": "com.yourcompany.yourapp",
"productName": "My Awesome App",
"directories": {
"output": "dist"
}
}
}Building for Windows
For Windows, electron-builder can create various targets. The most common are nsis (Nullsoft Scriptable Install System) for a standard installer, or portable for a single executable that doesn't require installation.
You can specify the target when running the build command:
npm run build -- --win nsisBuilding for macOS
On macOS, typical distribution formats include dmg (Disk Image) for a guided installation, or zip for a direct archive of the .app bundle.
It's also good practice to specify a category for macOS apps.
npm run build -- --mac dmgBuilding for Linux
Linux offers several packaging formats to cater to different distributions:
deb: For Debian-based systems (like Ubuntu).rpm: For Red Hat-based systems (like Fedora).AppImage: A universal format that runs on most Linux distributions.
Here's how to build an AppImage:
npm run build -- --linux AppImageCustomizing with Icons
A custom application icon is essential for brand recognition. You can specify a single icon path in your package.json's build section. electron-builder will automatically generate different sizes for various platforms.
It's recommended to place your main icon (e.g., a .png) in a build directory in your project root.
{
"build": {
"appId": "com.yourcompany.yourapp",
"productName": "My Awesome App",
"directories": {
"output": "dist"
},
"icon": "build/icon.png"
}
}Run Your Build!
With your package.json configured, executing the build command is straightforward. This command will start the packaging process, which might take a few minutes depending on your project size and internet speed (to download Electron binaries).
Once complete, you'll find your packaged application files in the dist directory.
npm run buildPackaging Features Quiz
Which of these are valid reasons to use electron-builder for packaging your Electron app?
Recap: Ready for Distribution
You've learned the essentials of packaging your Electron application!
- Packaging bundles your app into a distributable format.
electron-builderis the go-to tool for cross-platform packaging.- Configuration happens in
package.json, defining app metadata and build targets. - You can create installers for Windows (
nsis), macOS (dmg), and various Linux formats (AppImage,deb,rpm).
Now your app is ready to be shared with the world!
よくある質問
「Electronアプリのパッケージ化」レッスンは無料ですか?
はい。「Electronアプリのパッケージ化」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Electron Desktop App Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Electron Desktop App Developmentコースには全4レッスンが含まれています。
「Electronアプリのパッケージ化」で何を学びますか?
`electron-builder`などのツールを使い、さまざまなOS(Windows、macOS、Linux)向けにElectronアプリケーションを配布用パッケージにする方法を学びます。 ブラウザで直接実行するハンズオンコードでElectron Desktop App Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Electron Desktop App Developmentを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのElectron Desktop App Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「Electronアプリのパッケージ化」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このElectron Desktop App Developmentレッスンでコードを書いて実行できますか?
はい。すべてのElectron Desktop App Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- mainプロセスとrendererプロセス
- プロセス間通信(IPC)
- Electronアプリのパッケージ化
- 複数ウィンドウの管理