use rspack_hook::{plugin, plugin_hook};
use rspack_core::{Plugin, PluginContext, ApplyContext, CompilerOptions};
use rspack_core::CompilerCompilation;
use rspack_error::Result;
// define the plugin
#[plugin]
pub struct MyPlugin {
options: MyPluginOptions
}
// define the plugin hook
#[plugin_hook(CompilerCompilation for MuPlugin)]
async fn compilation(&self, compilation: &mut Compilation) -> Result<()> {
// do something...
}
// implement apply method for the plugin
impl Plugin for MyPlugin {
fn apply(&self, ctx: PluginContext<&mut ApplyContext>, _options: &mut CompilerOptions) -> Result<()> {
ctx.context.compiler_hooks.tap(compilation::new(self))
Ok(())
}
}