mirror of
https://github.com/alex8088/electron-vite.git
synced 2026-11-04 15:59:44 +08:00
29 lines
806 B
TypeScript
29 lines
806 B
TypeScript
import { build as viteBuild } from 'vite'
|
|
import { type InlineConfig, resolveConfig } from './config'
|
|
|
|
/**
|
|
* Bundles the electron app for production.
|
|
*/
|
|
export async function build(inlineConfig: InlineConfig = {}): Promise<void> {
|
|
process.env.NODE_ENV_ELECTRON_VITE = 'production'
|
|
const config = await resolveConfig(inlineConfig, 'build', 'production')
|
|
|
|
if (!config.config) {
|
|
return
|
|
}
|
|
|
|
// Build targets in order: main -> preload -> renderer
|
|
const buildTargets = ['main', 'preload', 'renderer'] as const
|
|
|
|
for (const target of buildTargets) {
|
|
const viteConfig = config.config[target]
|
|
if (viteConfig) {
|
|
// Disable watch mode in production builds
|
|
if (viteConfig.build?.watch) {
|
|
viteConfig.build.watch = null
|
|
}
|
|
await viteBuild(viteConfig)
|
|
}
|
|
}
|
|
}
|