
Bun Macros
Bun macros let you run JavaScript at bundle time and inline the results directly into your output code. Think embedding environment variables, reading files, generating code from schemas, or pulling git commit hashes without any runtime overhead. The macro runs once during bundling and vanishes, leaving only its return value. It's genuinely useful for things like pre-computing build metadata or eliminating dead code branches based on compile-time conditions. The catch is macros only work during `bun build`, not `bun run`, so you're committing to a bundling step. If you're already bundling and want to move work from runtime to build time, this handles the common cases cleanly.
- skills.sh installs
- 322
- GitHub stars
- 248
- last updated
- Aug 21, 2026
Install
$ npx -y skills add secondsky/claude-skills --skill bun-macros --agent claude-codeInstalls into .claude/skills of the current project.
Files
Bun Macros
Bun macros run JavaScript at bundle time and inline the results into the output.
Quick Start
// src/config.ts (macro file)
export function getVersion() {
return "1.0.0";
}
export function getBuildTime() {
return new Date().toISOString();
}
// src/index.ts (consumer)
import { getVersion, getBuildTime } from "./config" with { type: "macro" };
// At bundle time, these become:
const version = "1.0.0";
const buildTime = "2024-01-15T12:00:00.000Z";
Macro Syntax
// Import with macro attribute
import { fn } from "./macro-file" with { type: "macro" };
// Call the macro (evaluated at build time)
const result = fn();
Common Use Cases
Environment Inlining
// macros/env.ts
export function env(key: string): string {
return process.env[key] ?? "";
}
// src/index.ts
import { env } from "./macros/env" with { type: "macro" };
const apiUrl = env("API_URL");
// Becomes: const apiUrl = "https://api.example.com";
Git Information
// macros/git.ts
export function gitCommit(): string {
return Bun.spawnSync(["git", "rev-parse", "HEAD"])
.stdout.toString().trim();
}
Sponsors
Details
- Repository
- github.com/secondsky/claude-skills
- Category
- AI & Agent Building
- First seen
- Jun 3, 2026
More from secondsky/claude-skills
All 146- Cloudflare Workers Frameworks321
- Supabase Postgres Best Practices319
- Cloudflare Workers Ci Cd318
- Cloudflare Workers Dev Experience317
- Cloudflare Workers Observability315
- Cloudflare Workers Migration310
- Cloudflare Workers Multi Lang310
- Verification Before Completion310
- Nuxt Studio308
- Neon Vercel Postgres294
- Chrome Devtools288
- Database Sharding277
- Sveltia Cms277
- Google Gemini File Search272
- Tailwind V4 Shadcn8.2K
- Aceternity Ui1.6K
- Vitest Testing1.3K
- Motion1.1K
- Playwright1.1K
- Api Testing910
- Responsive Web Design703
- Zod663
- Nano Banana Prompts626
- Image Optimization604