40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import { rmSync } from 'node:fs'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const desktopRoot = join(__dirname, '..')
|
|
const outDir = join(desktopRoot, 'dist-electron')
|
|
|
|
rmSync(outDir, { recursive: true, force: true })
|
|
|
|
const mainBuild = await Bun.build({
|
|
entrypoints: [join(desktopRoot, 'src/main/index.ts')],
|
|
outdir: join(outDir, 'main'),
|
|
target: 'node',
|
|
format: 'cjs',
|
|
external: ['electron'],
|
|
minify: true,
|
|
naming: 'index.cjs',
|
|
})
|
|
|
|
if (!mainBuild.success) {
|
|
throw new AggregateError(mainBuild.logs, 'Electron main build failed')
|
|
}
|
|
|
|
const preloadBuild = await Bun.build({
|
|
entrypoints: [join(desktopRoot, 'src/preload/index.ts')],
|
|
outdir: join(outDir, 'preload'),
|
|
target: 'node',
|
|
format: 'cjs',
|
|
external: ['electron'],
|
|
minify: true,
|
|
naming: 'index.cjs',
|
|
})
|
|
|
|
if (!preloadBuild.success) {
|
|
throw new AggregateError(preloadBuild.logs, 'Electron preload build failed')
|
|
}
|
|
|
|
console.log('Built Electron main and preload to dist-electron/')
|