Bun Macros
Executes JavaScript at bundle time to inline static values, embed files, and optimize compile-time code generation.
Bun Macros streamlines build-time optimization by enabling developers to execute JavaScript functions during Bun's bundling phase and inline the evaluated results directly into production outputs. This skill provides guidance and implementation patterns for utilizing Bun's import attribute syntax (`with { type: 'macro' }`), embedding external assets and schemas, injecting environment variables safely, capturing Git metadata, and building dynamic route definitions without incurring runtime overhead.
主要功能
01Eliminates runtime overhead through compile-time route generation and dead code elimination
02239 GitHub stars
03Embeds static files, JSON schemas, and license texts directly into code
04Supports asynchronous execution for fetching remote schemas and APIs during builds
05Inlines arbitrary JavaScript and TypeScript expressions during bundling
06Injects Git metadata, build timestamps, and environment variables at compile time
使用场景
01Embedding static configurations, markdown files, or Git commit metadata directly into bundles
02Generating dynamic route mappings and API clients from local file schemas at build time
03Stripping dead platform code or conditional logic based on compile-time environment flags