0.1.2 • Published 29 days ago

bun-banner-plugin v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
29 days ago

bun-banner-plugin

A small plugin to insert an arbitrary string at the beginning of generated content. Inspired by esbuild banner option.

Installation

bun add -D bun-banner-plugin

Usage

build.ts:

import { bannerPlugin } from "bun-banner-plugin";

await Bun.build({
  entrypoints: ["src/index.ts"],
  outdir: "dist",
  target: "node",
  minify: true,
  plugins: [
    bannerPlugin({
      // Add banners to json files
      jsonc: ["// This is a jsonc file", "// Hello, jsonc!"],

      // Add a shebang to the top of `.ts`, `.tsx`, `.js`, `.jsx` files
      "ts|tsx|js|jsx": "#!/usr/bin/env node",
    }),
  ],
});

Example

Suppose you have the following src/index.ts.

console.log("Hello, world!");

Now, using the build.ts I wrote in Usage, run bun run build.ts, the following will be output:

#!/usr/bin/env node
console.log("Hello, world!");

Options

  • The key is a regular expression that matches the file extension.
    • The given key is interpreted as a regular expression, so you need to escape special characters.
    • For example:
      • If the key is json, it will interpreted as /.(json)$/. It will match .json files.
      • If the key is ts|tsx|js|jsx, it will iterpreted as /.(ts|tsx|js|jsx)$/. It will match .ts, .tsx, .js, .jsx files.
  • The value is the string to be inserted at the beginning of the file.

    • If the value is an array, the strings in the array will be joined with a newline character.
    • If the value is a string, it will be inserted as is.
    • For example, If the value is ["// This is a jsonc file", "// Hello, jsonc!"], it will be inserted as follows:

      // This is a jsonc file
      // Hello, jsonc!
      {
        "foo": "bar",
      }

Development

Commands

CommandDescription
bun installInstall dependencies
bun run buildBuild the project
bun run testRun tests with watch mode
bun run checkLint and format
npm publish --dry-runCheck locally for products to be published to npm
npm publish --access publicPublish to npm

Publish

  1. Update version in package.json
  2. commit with tag vX.X.X
  3. push to GitHub
0.1.2

29 days ago

0.1.1

6 months ago

0.1.0

6 months ago