Building and Packaging
Trufos uses Electron Forge as its primary tool for building, packaging, and distributing the application. The configuration for Electron Forge is located in forge.config.ts
.
Configuration (forge.config.ts
)
This file defines how Electron Forge handles the build and packaging process.
Key sections:
packagerConfig
: Options passed toelectron-packager
.asar: true
: Packages the application source code into an ASAR archive for potentially faster load times and to hide source code.icon: './images/icon'
: Specifies the path to the application icon (without extension, Electron Forge handles platform-specific formats like.icns
or.ico
).osxSign
&osxNotarize
: macOS specific signing and notarization settings. These are conditionally configured based on environment variables (APPLE_API_KEY
,APPLE_API_KEY_ID
,APPLE_API_ISSUER
), enabling code signing and notarization if credentials are provided.
-
rebuildConfig
: Configuration for rebuilding native Node modules (empty in this case, but important if native dependencies are used). makers
: Defines the types of distributables to create.MakerSquirrel
: Creates a Windows installer (Setup.exe
) using Squirrel.Windows.MakerZIP
: Creates a.zip
archive, configured here for Linux (['linux']
).MakerDMG
: Creates a.dmg
disk image for macOS.
plugins
:AutoUnpackNativesPlugin
: Automatically unpacks native Node modules from the ASAR archive, which is often necessary for them to function correctly.VitePlugin
: Integrates Vite for building the main and renderer process code.build
array: Configures Vite builds for non-renderer code.- Main process entry:
src/main/main.ts
with configsrc/main/vite.config.ts
. - Preload script entry:
src/main/preload.ts
with configsrc/main/vite.config.ts
.
- Main process entry:
renderer
array: Configures Vite builds for renderer process code.- Named
main_window
with entry point implicitly handled by Vite viaindex.html
and configsrc/renderer/vite.config.ts
.
- Named
FusesPlugin
: Allows toggling certain Electron security features at package time. This configuration enhances security by:- Disabling
RunAsNode
. - Enabling cookie encryption.
- Disabling Node.js options environment variables and CLI inspect arguments.
- Enabling ASAR integrity validation and ensuring the app only loads from ASAR.
- Disabling
publishers
: Configures how and where to publish releases.@electron-forge/publisher-github
: Configured to publish releases to GitHub under theEXXETA/trufos
repository, marked as prereleases.
Build Process Commands
Defined in package.json
:
yarn package
:- Runs
electron-forge package
. - Builds the application and packages it into a platform-specific runnable format (e.g., an
.app
bundle on macOS, anexe
with associated files on Windows) in theout/
directory. This is an unpackaged version, not an installer.
- Runs
yarn run make
:- Runs
electron-forge make
. - First, it performs the packaging step (like
yarn package
). - Then, it uses the specified
makers
(MakerSquirrel, MakerZIP, MakerDMG) to create distributable installers/archives (e.g.,Setup.exe
,.dmg
,.zip
) in theout/make/
directory.
- Runs
yarn publish
:- Runs
electron-forge publish
. - Builds, makes, and then publishes the application according to the
publishers
configuration (in this case, to GitHub Releases).
- Runs
How Vite is Used
The VitePlugin
in forge.config.ts
orchestrates the use of Vite:
- Main Process & Preload Script:
- Vite is configured in library mode for these entries (
src/main/main.ts
,src/main/preload.ts
). - The output is placed in
.vite/build/
(e.g.,.vite/build/main.js
,.vite/build/preload.js
). - Electron Forge then uses these built files when packaging the application.
- Vite is configured in library mode for these entries (
- Renderer Process:
- Vite builds the React application (
src/renderer/
). - The output (HTML, JS, CSS assets) is placed in
.vite/renderer/main_window_vite_renderer/
. - Electron Forge includes these assets in the packaged application, and the main window loads the
index.html
from this location.
- Vite builds the React application (
During development (yarn start
), electron-forge start
uses Vite’s development server for HMR (Hot Module Replacement) for the renderer process and rebuilds main/preload scripts as needed.