Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kravetsone/esbuild-plugin-autoload
Bun/esbuild plugin for work with autoload at runtime
https://github.com/kravetsone/esbuild-plugin-autoload
autoload bun-plugin elysia esbuild-plugin plugin
Last synced: 3 months ago
JSON representation
Bun/esbuild plugin for work with autoload at runtime
- Host: GitHub
- URL: https://github.com/kravetsone/esbuild-plugin-autoload
- Owner: kravetsone
- Created: 2024-06-15T17:57:51.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-07-17T12:32:12.000Z (4 months ago)
- Last Synced: 2024-07-17T15:23:56.940Z (4 months ago)
- Topics: autoload, bun-plugin, elysia, esbuild-plugin, plugin
- Language: TypeScript
- Homepage:
- Size: 37.1 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# esbuild-plugin-autoload
This [esbuild](https://esbuild.github.io/)/[Bun](https://bun.sh/docs/bundler) bundler plugin helps to use libraries for `autoload` endpoints, command and etc. At the build stage, it obtains what needs to be `import`-ed and includes it in the final file
> [!WARNING]
> For now, it runs only by [Bun](https://bun.sh/) runtime# [Bun build](https://bun.sh/docs/bundler) usage
```ts
// @filename: build.ts
import { autoload } from "esbuild-plugin-autoload"; // default import also supportedawait Bun.build({
entrypoints: ["src/index.ts"],
target: "bun",
outdir: "out",
plugins: [autoload()],
}).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 supportedawait Bun.build({
entrypoints: ["src/index.ts"],
target: "bun",
outdir: "out",
plugins: [autoload()],
}).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))## Options
| Key | Type | Default | Description |
| ---------- | ------ | ---------------------------------- | ------------------------------------------------------------------- |
| pattern? | string | "\*\*\/\*.{ts,tsx,js,jsx,mjs,cjs}" | [Glob patterns]() |
| directory? | string | "./src/routes" | The folder where something that will be autoloaded are located |You can also pass the directory by the first argument instead of an object with full options
```ts
await Bun.build({
entrypoints: ["src/index.ts"],
target: "bun",
outdir: "out",
plugins: [autoload("./src/commands")],
}).then(console.log);
```### [esbuild](https://esbuild.github.io/) usage
```ts
// @filename: build.ts
import { autoload } from "esbuild-plugin-autoload"; // default import also supported
import esbuild from "esbuild";await esbuild
.build({
entrypoints: ["src/index.ts"],
outdir: "out",
bundle: true,
plugins: [autoload()],
})
.then(console.log);
```Then, build it with `bun build.ts` and run with `bun out/index.ts`
### Supported `autoload`-ers
Sadly, this plugin can only work with supported libraries.
- [`elysia-autoload`](https://github.com/kravetsone/elysia-autoload)
- [`@gramio/autoload`](https://github.com/gramiojs/autoload)