bun-macros

Solid

Evaluate JavaScript at bundle time and inline results. Use when optimizing compile-time code generation, embedding files, inlining environment variables, or executing code during the bundling process.

Data & Documents 168 stars 27 forks Updated 4 weeks ago MIT

Install

View on GitHub

Quality Score: 89/100

Stars 20%
74
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Bun Macros Bun macros run JavaScript at bundle time and inline the results into the output. ## Quick Start ```typescript // 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 ```typescript // 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 ```typescript // 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 ```typescript // macros/git.ts export function gitCommit(): string { return Bun.spawnSync(["git", "rev-parse", "HEAD"]) .stdout.toString().trim(); } export function gitBranch(): string { return Bun.spawnSync(["git", "branch", "--show-current"]) .stdout.toString().trim(); } // src/index.ts import { gitCommit, gitBranch } from "./macros/git" with { type: "macro" }; const BUILD_INFO = { commit: gitCommit(), branch: gitBranch(), }; // Inlined at build ti...

Details

Author
secondsky
Repository
secondsky/claude-skills
Created
7 months ago
Last Updated
4 weeks ago
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category