Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
unplugin/unplugin-macrosWorks with
•JSR Score100%•This package works with Node.js, BunIt is unknown whether this package works with Cloudflare Workers, Deno



Downloads77/wk
•Publisheda month ago (0.18.6)
Macros plugin for bundlers.
unplugin-macros
Macros are a mechanism for running JavaScript functions at bundle-time. The value returned from these functions or variables are directly inlined into your bundle.
Installation
# npm npm i -D unplugin-macros # jsr npx jsr add -D @unplugin/macros
Vite
// vite.config.ts import Macros from 'unplugin-macros/vite' export default defineConfig({ plugins: [Macros()], })
Rollup
// rollup.config.js import Macros from 'unplugin-macros/rollup' export default { plugins: [Macros()], }
esbuild
Requires esbuild >= 0.15
// esbuild.config.js import { build } from 'esbuild' build({ plugins: [require('unplugin-macros/esbuild')()], })
Webpack
// webpack.config.js module.exports = { /* ... */ plugins: [require('unplugin-macros/webpack')()], }
Usage
// main.js import { buildTime, getRandom } from './macros' with { type: 'macro' } getRandom() // Will be replaced with a random number at build time buildTime // Will be replaced with the timestamp at the build time
// macros.js export function getRandom() { return Math.random() } export const buildTime = Date.now()
See more in Bun Macros.
TypeScript
Import Attributes syntax is supported in TypeScript 5.3 and above.
ESLint
Import Attributes syntax is supported in ESLint v9.14.0.
Options
Refer to docs.
Thanks
Thanks to Bun Macros.
Sponsors
License
MIT License © 2023-PRESENT Kevin Deng
Built and signed on
GitHub Actions