diff --git a/crates/binding/src/js_hook.rs b/crates/binding/src/js_hook.rs index 21ba89ac0..a9b827436 100644 --- a/crates/binding/src/js_hook.rs +++ b/crates/binding/src/js_hook.rs @@ -60,6 +60,8 @@ pub struct JsHooks { pub _on_generate_file: Option, #[napi(ts_type = "() => Promise;")] pub build_start: Option, + #[napi(ts_type = "() => Promise;")] + pub build_end: Option, #[napi( ts_type = "(source: string, importer: string, { isEntry: bool }) => Promise<{ id: string }>;" )] @@ -74,6 +76,7 @@ pub struct JsHooks { pub struct TsFnHooks { pub build_start: Option>, + pub build_end: Option>, pub generate_end: Option>, pub load: Option>>, pub load_include: Option>>, @@ -90,6 +93,9 @@ impl TsFnHooks { build_start: hooks.build_start.as_ref().map(|hook| unsafe { ThreadsafeFunction::from_napi_value(env.raw(), hook.raw()).unwrap() }), + build_end: hooks.build_end.as_ref().map(|hook| unsafe { + ThreadsafeFunction::from_napi_value(env.raw(), hook.raw()).unwrap() + }), generate_end: hooks.generate_end.as_ref().map(|hook| unsafe { ThreadsafeFunction::from_napi_value(env.raw(), hook.raw()).unwrap() }), diff --git a/crates/binding/src/js_plugin.rs b/crates/binding/src/js_plugin.rs index 2e561ad49..c0cdf4068 100644 --- a/crates/binding/src/js_plugin.rs +++ b/crates/binding/src/js_plugin.rs @@ -104,9 +104,14 @@ impl Plugin for JsPlugin { } fn generate_end(&self, param: &PluginGenerateEndParams, _context: &Arc) -> Result<()> { + // keep generate_end for compatibility + // since build_end does not have none error params in unplugin's api spec if let Some(hook) = &self.hooks.generate_end { hook.call(serde_json::to_value(param)?)? } + if let Some(hook) = &self.hooks.build_end { + hook.call(())? + } Ok(()) } diff --git a/docs/config.md b/docs/config.md index dc2f89e56..1e2b05b58 100644 --- a/docs/config.md +++ b/docs/config.md @@ -562,6 +562,7 @@ Specify the plugins to use. { name?: string; buildStart?: () => void; + buildEnd?: () => void; generateEnd?: (data: { isFirstCompile: boolean; time: number; diff --git a/docs/config.zh-CN.md b/docs/config.zh-CN.md index 9da777168..60c1cbed0 100644 --- a/docs/config.zh-CN.md +++ b/docs/config.zh-CN.md @@ -560,6 +560,7 @@ import(/* webpackIgnore: true */ "./foo"); { name?: string; buildStart?: () => void; + buildEnd?: () => void; generateEnd?: (data: { isFirstCompile: boolean; time: number;