esbuild-plugin-autoload
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

esbuild-plugin-autoload

This esbuild/Bun 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 runtime

Bun build usage

// @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()],
}).then(console.log);

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

You can bundle and then compile it into a single executable binary file

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

await 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)

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

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

esbuild usage

// @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.

Package Sidebar

Install

npm i esbuild-plugin-autoload

Weekly Downloads

43

Version

0.2.1

License

none

Unpacked Size

7.22 kB

Total Files

4

Last publish

Collaborators

  • skravets