{"id":22489242,"url":"https://github.com/unplugin/unplugin-macros","last_synced_at":"2026-02-27T11:57:00.810Z","repository":{"id":172153959,"uuid":"648260283","full_name":"unplugin/unplugin-macros","owner":"unplugin","description":"Macros plugin for bundlers.","archived":false,"fork":false,"pushed_at":"2026-02-02T20:42:09.000Z","size":1654,"stargazers_count":266,"open_issues_count":3,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-02-03T10:42:50.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://jsr.io/@unplugin/macros","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unplugin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"sxzz"}},"created_at":"2023-06-01T14:59:57.000Z","updated_at":"2026-02-02T20:42:12.000Z","dependencies_parsed_at":"2023-10-03T04:30:59.497Z","dependency_job_id":"90538fad-b6dd-437c-93f9-da5f28ad918d","html_url":"https://github.com/unplugin/unplugin-macros","commit_stats":null,"previous_names":["sxzz/unplugin-macros","unplugin/unplugin-macros"],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/unplugin/unplugin-macros","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unplugin%2Funplugin-macros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unplugin%2Funplugin-macros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unplugin%2Funplugin-macros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unplugin%2Funplugin-macros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unplugin","download_url":"https://codeload.github.com/unplugin/unplugin-macros/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unplugin%2Funplugin-macros/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29893235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T09:48:51.284Z","status":"ssl_error","status_checked_at":"2026-02-27T09:48:43.992Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T17:19:29.526Z","updated_at":"2026-02-27T11:57:00.805Z","avatar_url":"https://github.com/unplugin.png","language":"TypeScript","readme":"# unplugin-macros\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![JSR][jsr-src]][jsr-href]\n[![Unit Test][unit-test-src]][unit-test-href]\n\n\u003e Macros are a mechanism for running JavaScript functions at bundle-time.\n\u003e The value returned from these functions or variables are directly inlined into your bundle.\n\n## Installation\n\n```bash\n# npm\nnpm i -D unplugin-macros\n\n# jsr\nnpx jsr add -D @unplugin/macros\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eVite\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// vite.config.ts\nimport Macros from 'unplugin-macros/vite'\n\nexport default defineConfig({\n  plugins: [Macros()],\n})\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eRollup\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// rollup.config.js\nimport Macros from 'unplugin-macros/rollup'\n\nexport default {\n  plugins: [Macros()],\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eesbuild\u003c/summary\u003e\u003cbr\u003e\n\nRequires esbuild \u003e= 0.15\n\n```ts\n// esbuild.config.js\nimport { build } from 'esbuild'\n\nbuild({\n  plugins: [require('unplugin-macros/esbuild')()],\n})\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWebpack\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// webpack.config.js\nmodule.exports = {\n  /* ... */\n  plugins: [require('unplugin-macros/webpack')()],\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n## Usage\n\n```js\n// main.js\nimport { buildTime, getRandom } from './macros' with { type: 'macro' }\n\ngetRandom() // Will be replaced with a random number at build time\nbuildTime // Will be replaced with the timestamp at the build time\n```\n\n```js\n// macros.js\nexport function getRandom() {\n  return Math.random()\n}\nexport const buildTime = Date.now()\n```\n\n### Function Arguments\n\nYou can pass function values as arguments to macros. Functions must be isolated (no references to outside identifiers):\n\n```js\n// main.js\nimport { transform } from './macros' with { type: 'macro' }\n\ntransform(() =\u003e 42)\ntransform(async () =\u003e await Promise.resolve(42))\n```\n\nSee more in [Bun Macros](https://bun.sh/blog/bun-macros).\n\n### TypeScript\n\nImport Attributes syntax is supported in TypeScript 5.3 and above.\n\n### ESLint\n\nImport Attributes syntax is supported in ESLint v9.14.0.\n\n## Options\n\nRefer to [docs](https://jsr.io/@unplugin/macros/doc/api/~/Options).\n\n## Thanks\n\nThanks to [Bun Macros](https://bun.sh/blog/bun-macros).\n\n## Sponsors\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg\"\u003e\n    \u003cimg src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## License\n\n[MIT](./LICENSE) License © 2023-PRESENT [Kevin Deng](https://github.com/sxzz)\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/unplugin-macros.svg\n[npm-version-href]: https://npmjs.com/package/unplugin-macros\n[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin-macros\n[npm-downloads-href]: https://www.npmcharts.com/compare/unplugin-macros?interval=30\n[jsr-src]: https://jsr.io/badges/@unplugin/macros\n[jsr-href]: https://jsr.io/@unplugin/macros\n[unit-test-src]: https://github.com/unplugin/unplugin-macros/actions/workflows/unit-test.yml/badge.svg\n[unit-test-href]: https://github.com/unplugin/unplugin-macros/actions/workflows/unit-test.yml\n","funding_links":["https://github.com/sponsors/sxzz"],"categories":["TypeScript","Plugins"],"sub_categories":["Unplugin"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funplugin%2Funplugin-macros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funplugin%2Funplugin-macros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funplugin%2Funplugin-macros/lists"}