{"id":21396795,"url":"https://github.com/favware/esbuild-plugin-version-injector","last_synced_at":"2025-07-13T19:31:25.862Z","repository":{"id":61074530,"uuid":"547432838","full_name":"favware/esbuild-plugin-version-injector","owner":"favware","description":"An esbuild plugin to inject your application's version number or today's date into your files","archived":false,"fork":false,"pushed_at":"2025-07-13T01:02:52.000Z","size":13229,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-13T01:05:21.679Z","etag":null,"topics":["esbuild","esbuild-plugin","hacktoberfest","javascript","plugin","typescript"],"latest_commit_sha":null,"homepage":"","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/favware.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["favna"],"patreon":"favna","open_collective":null,"ko_fi":"favna","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://donate.favware.tech/paypal"}},"created_at":"2022-10-07T17:17:19.000Z","updated_at":"2025-07-13T01:02:55.000Z","dependencies_parsed_at":"2023-12-31T01:40:47.227Z","dependency_job_id":"6b6f4f8c-e0e3-4331-9fec-7b1df7657d5f","html_url":"https://github.com/favware/esbuild-plugin-version-injector","commit_stats":{"total_commits":84,"total_committers":4,"mean_commits":21.0,"dds":0.3928571428571429,"last_synced_commit":"3db91e33d399c3ca4869dfa03457b40c91e26f1a"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":"sapphiredev/sapphire-template","purl":"pkg:github/favware/esbuild-plugin-version-injector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-version-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-version-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-version-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-version-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/favware","download_url":"https://codeload.github.com/favware/esbuild-plugin-version-injector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-version-injector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265093151,"owners_count":23710235,"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":["esbuild","esbuild-plugin","hacktoberfest","javascript","plugin","typescript"],"created_at":"2024-11-22T14:29:17.681Z","updated_at":"2025-07-13T19:31:25.454Z","avatar_url":"https://github.com/favware.png","language":"TypeScript","funding_links":["https://github.com/sponsors/favna","https://patreon.com/favna","https://ko-fi.com/favna","https://donate.favware.tech/paypal","https://github.com/sponsors/Favna"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# esbuild-plugin-version-injector\n\n**An esbuild plugin to inject your application's version number or today's date\ninto your files**\n\n[![GitHub](https://img.shields.io/github/license/favware/esbuild-plugin-version-injector)](https://github.com/favware/esbuild-plugin-version-injector/blob/main/LICENSE.md)\n[![npm](https://img.shields.io/npm/v/esbuild-plugin-version-injector?color=crimson\u0026logo=npm\u0026style=flat-square)](https://www.npmjs.com/package/esbuild-plugin-version-injector)\n\n\u003c/div\u003e\n\n_This plugin was inspired by\n[rollup-plugin-version-injector](https://github.com/djhouseknecht/rollup-plugin-version-injector)_\n\n**Table of Contents**\n\n- [esbuild-plugin-version-injector](#esbuild-plugin-version-injector)\n  - [Description](#description)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [With `esbuild`](#with-esbuild)\n    - [With `tsup`](#with-tsup)\n  - [File Injection examples](#file-injection-examples)\n    - [JavaScript / TypeScript](#javascript--typescript)\n    - [JSON](#json)\n    - [CSS](#css)\n    - [Text](#text)\n  - [Options](#options)\n  - [Buy us some doughnuts](#buy-us-some-doughnuts)\n  - [Contributors](#contributors)\n\n## Description\n\nThere are many ways to export a constant that holds your package variable, from\nloading your own package.json through a `fs.readFile`, importing the\npackage.json directly, or manually updating a constant on every bump. However\nall of these have their downsides, and this plugin aims to solve that.\n\n- `fs.readFile` is an addition file operation that the end-user's system has to\n  deal with and causes slow downs.\n- importing the package.json directly can cause issues with interoperability\n  between CJS and ESM as the latter requires JSON assertions.\n  - Alternatively when using a bundler that inlines the package.json code that\n    means the bundle ends up increasing in size unnecessarily for only having to\n    include the version field\n- Manually updating a constant on every bump is a chore and can be easily\n  forgotten.\n\nThis plugin aims to solve all of these issues by injecting the version number\nand/or today's date directly into your built JavaScript files during the\nbundling step provided by esbuild. This plugin can therefore work with many of\nthe famous bundlers such as esbuild directly, tsup, vite, or other bundlers that\nalso use esbuild under the hood.\n\n## Installation\n\nYou can use the following command to install this package, or replace\n`npm install -D` with your package manager of choice.\n\n```sh\nnpm install -D esbuild-plugin-version-injector\n```\n\n## Usage\n\n### With [`esbuild`][esbuild]\n\nAdd the plugin to your esbuild options, i.e.:\n\n```js\nconst esbuild = require('esbuild');\nconst { resolve } = require('path');\nconst {\n  esbuildPluginVersionInjector\n} = require('esbuild-plugin-version-injector');\n\nawait esbuild.build({\n  format: 'cjs',\n  entryPoints: [resolve(__dirname, './src/index.ts')],\n  outdir: resolve(__dirname, './dist'),\n  plugins: [esbuildPluginVersionInjector()]\n});\n```\n\n### With [`tsup`][tsup]\n\nAdd the plugin to your `tsup.config.ts`, i.e.:\n\n```js\nimport { defineConfig } from 'tsup';\nimport { resolve } from 'path';\nimport { esbuildPluginVersionInjector } from 'esbuild-plugin-version-injector';\n\nawait defineConfig({\n  format: ['cjs'],\n  entry: ['./src/index.ts'],\n  outDir: './dist',\n  esbuildPlugins: [esbuildPluginVersionInjector()]\n});\n```\n\n[esbuild]: https://esbuild.github.io/\n[tsup]: https://tsup.egoist.dev\n\n## File Injection examples\n\n### JavaScript / TypeScript\n\n```ts\n/**\n * The current version that you are currently using.\n *\n * Note to developers: This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '[VI]{{inject}}[/VI]';\n```\n\n### JSON\n\n```json\n{\n  \"version\": \"[VI]{{inject}}[/VI]\"\n}\n```\n\n### CSS\n\n```css\n.myClass {\n  content: '[VI]{{inject}}[/VI]';\n}\n```\n\n**_A note regarding using CSS preprocessors (SASS / LESS / Stylus / etc)_**:\nWhen using a CSS preprocessor you might be using an esbuild plugin like\n[`esbuild-sass-plugin`](https://www.npmjs.com/package/esbuild-sass-plugin). This\ncauses the CSS to be processed before this plugin can inject the version number\nand at the moment esbuild now will no longer pass the file to be processed by\nthis plugin. To solve this you will have to build your code twice with esbuild,\nonce with the CSS preprocessor plugin and once with this plugin. This can be\ndone by using the `build` function twice, or by using the `buildSync` function\ntwice. An example of this can be found at the test to cover this case\n[here](./tests/scenarios/css/sass-parsing.test.ts).\n\n### Text\n\n```txt\nThis document is for version [VI]{{inject}}[/VI]\n```\n\n## Options\n\nThe plugin accepts the following options:\n\n- `versionOrCurrentDate`: One of `'version'`, `'current-date'` or one of the\n  entries of the `VersionOrCurrentDate` enum. Defaults to `'version'`. This\n  determines what format to inject into your built files. If this is set to\n  `current-date` then the current date in the\n  [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) will be inserted instead of\n  the package.json version.\n\n- `injectTag`: The tag that should be searched for and replaced across your\n  code. Defaults to `'[VI]{{inject}}[/VI]'`. This can be any string, but it is\n  recommended to use something that is unlikely to be used in your code.\n\n- `packageJsonPath` The relative path to your package.json file. Defaults to\n  `'./package.json'`. This is used to read the version number from your\n  package.json file.\n\n- `filter`: This is an advanced use-case option with which you can filter which\n  files esbuild should apply this plugin on\n\n- `namespace`: This is an advanced use-case option through which the\n  [esbuild namespace](https://esbuild.github.io/plugins/#namespaces) can be\n  configured\n\n## Buy us some doughnuts\n\nFavware projects are and always will be open source, even if we don't get\ndonations. That being said, we know there are amazing people who may still want\nto donate just to show their appreciation. Thank you very much in advance!\n\nWe accept donations through Ko-fi, Paypal, Patreon, GitHub Sponsorships, and\nvarious cryptocurrencies. You can use the buttons below to donate through your\nmethod of choice.\n\n|   Donate With   |                      Address                      |\n| :-------------: | :-----------------------------------------------: |\n|      Ko-fi      |  [Click Here](https://donate.favware.tech/kofi)   |\n|     Patreon     | [Click Here](https://donate.favware.tech/patreon) |\n|     PayPal      | [Click Here](https://donate.favware.tech/paypal)  |\n| GitHub Sponsors |  [Click Here](https://github.com/sponsors/Favna)  |\n|     Bitcoin     |       `1E643TNif2MTh75rugepmXuq35Tck4TnE5`        |\n|    Ethereum     |   `0xF653F666903cd8739030D2721bF01095896F5D6E`    |\n|    LiteCoin     |       `LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6`        |\n\n## Contributors\n\nPlease make sure to read the [Contributing Guide][contributing] before making a\npull request.\n\nThank you to all the people who already contributed!\n\n\u003ca href=\"https://github.com/favware/esbuild-plugin-version-injector/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=favware/esbuild-plugin-version-injector\" /\u003e\n\u003c/a\u003e\n\n[contributing]: .github/CONTRIBUTING.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavware%2Fesbuild-plugin-version-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffavware%2Fesbuild-plugin-version-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavware%2Fesbuild-plugin-version-injector/lists"}