From 4332474ed600b47bed235cd53d2b1ce961ba9bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B8=85=E8=A5=BF?= <928200407@qq.com> Date: Fri, 11 Oct 2024 00:24:56 +0800 Subject: [PATCH] fix(plugin-vite): stop the world --- packages/plugin/vite/src/VitePlugin.ts | 2 +- packages/plugin/vite/src/util/plugins.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) 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; }