Skip to content

Commit

Permalink
chore: add info about Bun.build
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Jun 16, 2024
1 parent 15a76b4 commit 3c42b96
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![JSR](https://jsr.io/badges/@gramio/autoload)](https://jsr.io/@gramio/autoload)
[![JSR Score](https://jsr.io/badges/@gramio/autoload/score)](https://jsr.io/@gramio/autoload)

Autoload commands plugin for GramIO.
Autoload commands plugin for GramIO with [`Bun.build`](#bun-build-usage) support.

## Usage

Expand Down Expand Up @@ -49,3 +49,43 @@ export default (bot: BotType) =>
| onFinish? | (paths: { absolute: string; relative: string }[]) => unknown; | | the hook that is called after loading all files |

and other [glob package options](https://www.npmjs.com/package/glob#options)

### [Bun build](https://bun.sh/docs/bundler) usage

You can use this plugin with [`Bun.build`](https://bun.sh/docs/bundler), thanks to [esbuild-plugin-autoload](https://github.com/kravetsone/esbuild-plugin-autoload)!

```ts
// @filename: build.ts
import { autoload } from "esbuild-plugin-autoload"; // default import also supported

await Bun.build({
entrypoints: ["src/index.ts"],
target: "bun",
outdir: "out",
plugins: [autoload("./src/commands")],
}).then(console.log);
```

Then, build it with `bun build.ts` and run with `bun out/index.ts`.

### [Bun compile](https://bun.sh/docs/bundler/executables) usage

You can bundle and then compile it into a [single executable binary file](https://bun.sh/docs/bundler/executables)

```ts
import { autoload } from "esbuild-plugin-autoload"; // default import also supported

await Bun.build({
entrypoints: ["src/index.ts"],
target: "bun",
outdir: "out",
plugins: [autoload("./src/commands")],
}).then(console.log);

await Bun.$`bun build --compile out/index.js`;
```

> [!WARNING]
> You cannot use it in `bun build --compile` mode without extra step ([Feature issue](https://github.com/oven-sh/bun/issues/11895))
[Read more](https://github.com/kravetsone/esbuild-plugin-autoload)

0 comments on commit 3c42b96

Please sign in to comment.