{"id":19477072,"url":"https://github.com/swordjs/esbuild-plugin-condition-comment-macro","last_synced_at":"2025-04-25T14:32:30.520Z","repository":{"id":65810281,"uuid":"599623777","full_name":"swordjs/esbuild-plugin-condition-comment-macro","owner":"swordjs","description":"This is an esbuild plugin, which can be given a condition that will filter out unqualified macro comment blocks from the code. This is usually used for conditional builds","archived":false,"fork":false,"pushed_at":"2023-02-11T13:14:24.000Z","size":52,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-22T10:53:25.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swordjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-02-09T14:36:35.000Z","updated_at":"2024-10-11T10:43:37.000Z","dependencies_parsed_at":"2023-02-22T02:00:19.514Z","dependency_job_id":null,"html_url":"https://github.com/swordjs/esbuild-plugin-condition-comment-macro","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"12f44b8ae287141ce9ad2da86d910828ae73d0ae"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swordjs%2Fesbuild-plugin-condition-comment-macro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swordjs%2Fesbuild-plugin-condition-comment-macro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swordjs%2Fesbuild-plugin-condition-comment-macro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swordjs%2Fesbuild-plugin-condition-comment-macro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swordjs","download_url":"https://codeload.github.com/swordjs/esbuild-plugin-condition-comment-macro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250834206,"owners_count":21494929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-11-10T19:43:37.723Z","updated_at":"2025-04-25T14:32:30.502Z","avatar_url":"https://github.com/swordjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esbuild-plugin-condition-comment-macro\n\nThis is an esbuild plugin, which can be given a condition that will filter out unqualified macro comment blocks from the code. This is usually used for conditional builds\n\n## Installation\n\n```bash\nnpm install @swordjs/esbuild-plugin-condition-comment-macro -D\n```\n\nOr use yarn / pnpm\n\n\n## Usage\n\n```js\nimport * as esbuild from 'esbuild'\nimport { ConditionCommentMacroPlugin } from \"@swordjs/esbuild-plugin-condition-comment-macro\"\n\nconst condition = \"aliyun\"\n\nawait esbuild.build({\n  entryPoints: ['src/index.ts'],\n  outfile: 'dist/out.js',\n  plugins: [ConditionCommentMacroPlugin({\n    prefix: \"@\",\n    startMacro: {\n      ifdef: ({ match, args, reg }) =\u003e args.includes(condition) ? match : match.replace(reg, ''),\n      ifndef: ({ match, args, reg }) =\u003e args.includes(condition) ? match.replace(reg, '') : match,\n    },\n    endMacro: \"endif\"\n  })()]\n})\n```\n\nJust like `build.js` in the `test/fixture` folder, when using esbuild, just pass some necessary parameters to the plugin\n\nIn the above code, we simply implement a conditional compilation function, we set the condition to `aliyun`, and then write the following code in the code\n\n```js\n// @ifdef server || woker || aliyun\nconst test = 1\n// @endif\n// @ifdef aliyun\nconst a = 1\n// @endif\n// @ifndef aliyun || server\nconst b = 1\n// @endif\n```\n\nThen esbuild will output this code content\n\n```js\n\"use strict\";\nconst test = 1;\nconst a = 1;\n```\n\n\n\n## Options\n\n```ts\ninterface Options {\n    // Macro prefix, we recommend using @\n    prefix: string,\n    // A custom action on the start macro, which returns the current matching fragment, along with the macro parameters and the regular being matched\n    startMacro: Record\u003cstring, (params: {match: string, args: string[], reg: RegExp}) =\u003e string\u003e,\n    // End macro\n    endMacro: string,\n}\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswordjs%2Fesbuild-plugin-condition-comment-macro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswordjs%2Fesbuild-plugin-condition-comment-macro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswordjs%2Fesbuild-plugin-condition-comment-macro/lists"}