rspack_binding_builder_macros
Exports a few macros to help you create a custom plugin register with Rspack.
Important
This crate is used for creating a custom binding. It is not intended to be used directly by non-custom binding users.
Guide
Usage
register_plugin
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.
Parameters
register_plugin macro accepts two arguments:
- The name of the plugin
- A resolver function that returns a
rspack_core::BoxPlugin
The resolver function accepts two arguments:
env: The environment of the plugin, it is the same asnapi::bindgen_prelude::Envoptions: The options of the plugin, it is the same asnapi::bindgen_prelude::Unknown<'_>
The resolver function should return a rspack_core::BoxPlugin
Example
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;
use register_plugin;
register_plugin!;
;
The registerMyBannerPlugin function will be exposed to the final N-API binding.
const = require;
const plugin = ;
To actually use the plugin, you need to wrap it with require('@rspack/core').experiments.createNativePlugin:
require..