| Crates.io | rspack_binding_builder_macros |
| lib.rs | rspack_binding_builder_macros |
| version | 0.5.7 |
| created_at | 2025-07-04 17:44:07.241435+00 |
| updated_at | 2025-09-24 07:51:29.317716+00 |
| description | Rspack binding builder macros |
| homepage | https://rspack.rs/ |
| repository | https://github.com/web-infra-dev/rspack |
| max_upload_size | |
| id | 1738270 |
| size | 166,098 |
Exports a few macros to help you create a custom plugin register with Rspack.
This crate is used for creating a custom binding. It is not intended to be used directly by non-custom binding users.
Create a custom plugin register with Rspack.
The created plugin register will be exposed to the final N-API binding.
The plugin needs to be wrapped with require('@rspack/core').experiments.createNativePlugin
to be used in the host.
register_plugin macro accepts two arguments:
rspack_core::BoxPluginThe resolver function accepts two arguments:
env: The environment of the plugin, it is the same as napi::bindgen_prelude::Envoptions: The options of the plugin, it is the same as napi::bindgen_prelude::Unknown<'_>The resolver function should return a rspack_core::BoxPlugin
This example will expose registerMyBannerPlugin in the final N-API binding:
Note: The following example requires the
napi_derive,rspack_binding_builder_macros,rspack_core, andrspack_errorcrates, and is for illustration only. It may not compile without additional setup.
use napi_derive::napi;
use rspack_binding_builder_macros::register_plugin;
register_plugin!(
"MyBannerPlugin",
|env: napi::bindgen_prelude::Env, options: napi::bindgen_prelude::Unknown<'_>| {
Ok(Box::new(MyBannerPlugin) as rspack_core::BoxPlugin)
}
);
#[derive(Debug)]
struct MyBannerPlugin;
impl rspack_core::Plugin for MyBannerPlugin {
fn apply(&self, ctx: &mut rspack_core::ApplyContext<'_>) -> rspack_error::Result<()> {
Ok(())
}
}
The registerMyBannerPlugin function will be exposed to the final N-API binding.
const { registerMyBannerPlugin } = require('your-custom-binding');
const plugin = registerMyBannerPlugin();
To actually use the plugin, you need to wrap it with require('@rspack/core').experiments.createNativePlugin:
require('@rspack/core').experiments.createNativePlugin("MyBannerPlugin", (options) => options)