Skip to content

Commit

Permalink
Merge branch 'fix/wait-for-all-files' of https://github.com/CommandMC…
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Nov 4, 2023
2 parents 65b73c2 + ab990b9 commit 7f75ae2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function electron(options: ElectronOptions | ElectronOptions[]):
Object.assign(process.env, {
VITE_DEV_SERVER_URL: resolveServerUrl(server),
})
let closeBundleCount = 0
for (const options of optionsArray) {
options.vite ??= {}
options.vite.mode ??= server.config.mode
Expand All @@ -66,6 +67,18 @@ export default function electron(options: ElectronOptions | ElectronOptions[]):
{
name: ':startup',
closeBundle() {
/*
closeBundle is emitted for both the preload and main electron
files. If we simply run Electron once either one finishes,
the other one might not finish in time. Usually, the faster
one is the preload, meaning if main is *a lot* larger than it,
Electron might start before the file is done building,
leading to an "Unable to find Electron app at ..." error
*/
closeBundleCount++
if (closeBundleCount < optionsArray.length)
return

if (options.onstart) {
options.onstart.call(this, {
startup,
Expand Down

0 comments on commit 7f75ae2

Please sign in to comment.