Skip to content

Commit

Permalink
Update plugins.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Dec 17, 2024
1 parent f2e0d60 commit 1d48561
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions docs/bundler/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ Native plugins are NAPI modules which expose lifecycle hooks as C ABI functions.

To create a native plugin, you must export a C ABI function which matches the signature of the native lifecycle hook you want to implement.

ve bundler plugins are NAPI modules, the easiest way to get started is to create a new [napi-rs](https://github.com/napi-rs/napi-rs) project:

```bash
bun add -g @napi-rs/cli
napi new
Expand Down Expand Up @@ -358,6 +356,34 @@ pub fn replace_foo_with_bar(handle: &mut OnBeforeParse) -> Result<()> {
}
```

And to use it in Bun.build():

```typescript
import myNativeAddon from "./my-native-addon";
Bun.build({
entrypoints: ["./app.tsx"],
plugins: [
{
name: "my-plugin",

setup(build) {
build.onBeforeParse(
{
namespace: "file",
filter: "**/*.tsx",
},
{
napiModule: myNativeAddon,
symbol: "replace_foo_with_bar",
// external: myNativeAddon.getSharedState()
},
);
},
},
],
});
```

### `onBeforeParse`

```ts
Expand Down

0 comments on commit 1d48561

Please sign in to comment.