A small plugin to insert an arbitrary string at the beginning of generated content. Inspired by esbuild banner option.
bun add -D bun-banner-plugin
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",
}),
],
});
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!");
- 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.
- If the key is
- 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", }
-
Command | Description |
---|---|
bun install |
Install dependencies |
bun run build |
Build the project |
bun run test |
Run tests with watch mode |
bun run check |
Lint and format |
npm publish --dry-run |
Check locally for products to be published to npm |
npm publish --access public |
Publish to npm |
- Update version in
package.json
- commit with tag
vX.X.X
- push to GitHub