English
API
The electronup package exports:
| Export | Type | Description |
|---|---|---|
defineConfig | function | Config type helper |
initAutoUpdater | function | Initializes electron-updater |
checkForUpdates | function | Checks for updates |
autoUpdater | lazy proxy | Access to the electron-updater instance |
BuilderConfig | type | Alias for electron-builder config |
ConfigEnv | type | Argument type of the config function |
ElectronupConfig | type | Full config type |
PackConfig | type | Type of packConfig |
ViteConfig | type | Type of viteConfig |
AutoUpdaterOptions | type | Options of initAutoUpdater |
defineConfig
A typing helper that returns the config unchanged.
ts
import { defineConfig } from 'electronup'
export default defineConfig({
// ...
})Even without "type": "module" in package.json, ESM syntax works in the config file.
Conditional config
Pass a function when the config depends on the command (serve / build) or the project root:
ts
import { defineConfig } from 'electronup'
export default defineConfig(({ command, root }) => {
if (command === 'serve') {
return {
// dev-only options
}
}
return {
// build-only options
}
})command is 'serve' or 'build'; root is the project root where the CLI was started.
Async config
Return a promise or use an async function:
ts
export default defineConfig(async () => {
const data = await loadConfig()
return {
// config
}
})TIP
ConfigEnv contains command, mode (set by -m; development in dev and production in build by default) and root.
ConfigEnv
ts
interface ConfigEnv {
command: 'build' | 'serve'
mode: string
root: string
}initAutoUpdater
Configures the electron-updater instance and optionally checks for updates on start.
ts
import { initAutoUpdater } from 'electronup'
initAutoUpdater({
checkOnStart: true,
autoDownload: true,
autoInstallOnAppQuit: true,
logger: undefined,
})AutoUpdaterOptions:
ts
interface AutoUpdaterOptions {
/** Check right after init. Defaults to true. */
checkOnStart?: boolean
/** Download automatically once found. Defaults to true. */
autoDownload?: boolean
/** Install a downloaded update on quit. Defaults to true. */
autoInstallOnAppQuit?: boolean
/** Logger compatible with electron-updater. */
logger?: typeof autoUpdater.logger
}Returns the underlying electron-updater instance. Call it after app.whenReady(). The start-up check only fires when app.isPackaged is true.
checkForUpdates
Checks for updates and downloads according to the current configuration.
ts
import { checkForUpdates } from 'electronup'
const result = await checkForUpdates()When app.isPackaged === false, it resolves to null without a network request.
autoUpdater
A lazy proxy to the electron-updater instance for events and fine-grained control. initAutoUpdater returns the underlying instance, which is a different object from this proxy. Subscribe before initialization:
ts
import { autoUpdater } from 'electronup'
autoUpdater.on('update-available', (info) => {})
autoUpdater.on('update-downloaded', (info) => {})
autoUpdater.on('error', (error) => {})See the electron-updater docs for events and fields.
Config types
ts
import type {
AutoUpdaterOptions,
BuilderConfig,
ConfigEnv,
ElectronupConfig,
PackConfig,
ViteConfig,
} from 'electronup'See Configuration for every field and default.