
Product
Introducing Custom Pull Request Alert Comment Headers
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
unplugin-macros
Advanced tools
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.
# npm
npm i -D unplugin-macros
# jsr
npx jsr add -D @unplugin/macros
// vite.config.ts
import Macros from 'unplugin-macros/vite'
export default defineConfig({
plugins: [Macros()],
})
// rollup.config.js
import Macros from 'unplugin-macros/rollup'
export default {
plugins: [Macros()],
}
Requires esbuild >= 0.15
// esbuild.config.js
import { build } from 'esbuild'
build({
plugins: [require('unplugin-macros/esbuild')()],
})
// webpack.config.js
module.exports = {
/* ... */
plugins: [require('unplugin-macros/webpack')()],
}
// 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.
Import Attributes syntax is supported in TypeScript 5.3 and above.
Import Attributes syntax is supported in ESLint v9.14.0.
Refer to docs.
Thanks to Bun Macros.
MIT License © 2023-PRESENT Kevin Deng
FAQs
Macros for bundlers.
The npm package unplugin-macros receives a total of 1,820 weekly downloads. As such, unplugin-macros popularity was classified as popular.
We found that unplugin-macros demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.