diff --git a/packages/plugin/vite/src/VitePlugin.ts b/packages/plugin/vite/src/VitePlugin.ts index 821e511f61..81cb266b2d 100644 --- a/packages/plugin/vite/src/VitePlugin.ts +++ b/packages/plugin/vite/src/VitePlugin.ts @@ -164,7 +164,7 @@ the generated files). Instead, it is ${JSON.stringify(pj.main)}`); // Avoid recursive builds caused by users configuring @electron-forge/plugin-vite in Vite config file. configFile: false, ...userConfig, - plugins: [onBuildDone(resolve), ...(userConfig.plugins ?? [])], + plugins: [onBuildDone(resolve, reject), ...(userConfig.plugins ?? [])], }) .then((result) => { if (isWatcher(result)) { diff --git a/packages/plugin/vite/src/util/plugins.ts b/packages/plugin/vite/src/util/plugins.ts index 5bb0e0b256..3ed59d98a0 100644 --- a/packages/plugin/vite/src/util/plugins.ts +++ b/packages/plugin/vite/src/util/plugins.ts @@ -1,10 +1,19 @@ import type { Plugin } from 'vite'; -export function onBuildDone(callback: () => void) { +export function onBuildDone(onfulfilled: () => void, onrejected: (error: Error) => void) { return { name: '@electron-forge/plugin-vite:build-done', - closeBundle() { - callback(); + buildEnd(error) { + error && onrejected(error); + }, + generateBundle(options, bundle, isWrite) { + isWrite || onfulfilled(); + }, + writeBundle() { + onfulfilled(); + }, + renderError(error) { + error && onrejected(error); }, } as Plugin; }