bun-macros

Evaluate JavaScript functions at bundle time and inline serialized results into Bun build output.

Updated Jun 22, 2026
One-click install
npx skills add https://github.com/aicodepro/ai-agent-nexi --skill bun-macros-aicodepro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bun-macros
Source: https://github.com/aicodepro/ai-agent-nexi/tree/main/agent/skills/bun-macros
Command: npx skills add https://github.com/aicodepro/ai-agent-nexi --skill bun-macros-aicodepro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Build-time values like environment variables, git metadata, file contents, and generated code often require separate codegen scripts or runtime overhead. Bun macros let you execute JavaScript during the bundling process and inline the results directly into the output, eliminating runtime computation and manual pre-build steps. ## Core Features & Use Cases - Compile-Time Evaluation: Import functions with with { type: "macro" } so they execute during bun build and their return values are inlined as literals. - Environment and Git Inlining: Embed environment variables, git commit hashes, branch names, and build timestamps directly into the bundle. - File Embedding and Code Generation: Inline file contents, JSON configs, directory listings, and generated TypeScript types or API clients at build time. - Use Case: A web app needs its API URL and build version baked in. Define macros reading process.env.API_URL and git rev-parse HEAD, import them with the macro attribute, and the bundle contains the literal values with zero runtime lookups. ## Quick Start Ask the assistant to create a Bun macro that inlines an environment variable and the current git commit hash into your bundle at build time.

Frequently Asked Questions about bun-macros

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Bun macros to inline values at build time?

Export a function from a macro file, then import it with `import { fn } from "./file" with { type: "macro" }`. When you run `bun build`, the function executes and its return value is inlined as a literal in the output.

How to embed environment variables into a Bun bundle?

Create a macro that reads `process.env[key]` and returns the value, then import it with the macro attribute. The variable's value is inlined during bundling, and you can throw an error to fail the build if it is missing.

Do Bun macros run at runtime or only during bundling?

Bun macros only execute during bundling with `bun build`. Running the file directly with `bun run` does not evaluate macros, so the inlined values exist only in the built output.

What return types do Bun macros support?

Macros can return primitives, plain objects, arrays, null, and Response objects. Return values must be JSON-serializable; returning functions or classes causes a 'Not serializable' build error.

Why is my Bun macro not being evaluated?

The most common cause is a missing `with { type: "macro" }` import attribute. Also verify the import path is correct and that you are running `bun build`, since macros do not execute with `bun run`.