{"id":13452435,"url":"https://github.com/pirelenito/git-revision-webpack-plugin","last_synced_at":"2025-04-08T11:07:49.426Z","repository":{"id":4044209,"uuid":"51776517","full_name":"pirelenito/git-revision-webpack-plugin","owner":"pirelenito","description":"🏗 Webpack plugin that generates VERSION and COMMITHASH files during build","archived":false,"fork":false,"pushed_at":"2023-01-07T17:05:21.000Z","size":1490,"stargazers_count":359,"open_issues_count":9,"forks_count":48,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-01T09:26:10.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/git-revision-webpack-plugin","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/pirelenito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-15T18:34:05.000Z","updated_at":"2025-01-21T02:19:07.000Z","dependencies_parsed_at":"2023-01-13T12:54:38.004Z","dependency_job_id":null,"html_url":"https://github.com/pirelenito/git-revision-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirelenito%2Fgit-revision-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirelenito%2Fgit-revision-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirelenito%2Fgit-revision-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirelenito%2Fgit-revision-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pirelenito","download_url":"https://codeload.github.com/pirelenito/git-revision-webpack-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829491,"owners_count":21002995,"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-07-31T07:01:24.062Z","updated_at":"2025-04-08T11:07:49.400Z","avatar_url":"https://github.com/pirelenito.png","language":"TypeScript","readme":"# git-revision-webpack-plugin\n\n[![npm version](https://badge.fury.io/js/git-revision-webpack-plugin.svg)](https://badge.fury.io/js/git-revision-webpack-plugin)\n[![downloads](https://img.shields.io/npm/dm/git-revision-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/git-revision-webpack-plugin)\n[![Code Climate](https://codeclimate.com/github/pirelenito/git-revision-webpack-plugin/badges/gpa.svg)](https://codeclimate.com/github/pirelenito/git-revision-webpack-plugin)\n\nSimple [webpack](https://webpack.js.org/) plugin that generates `VERSION` and `COMMITHASH` files during build based on a local [git](http://www.git-scm.com/) repository.\n\n## Usage\n\nGiven a **webpack 5** project ([check below](#outdated-webpack) for **old webpack versions**), install it as a local development dependency:\n\n```bash\nnpm install --save-dev git-revision-webpack-plugin\n```\n\nThen, simply configure it as a plugin in the webpack config:\n\n```javascript\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\n\nmodule.exports = {\n  plugins: [new GitRevisionPlugin()],\n}\n```\n\nIt outputs a `VERSION` based on [git-describe](http://www.git-scm.com/docs/git-describe) such as:\n\n```\nv0.0.0-34-g7c16d8b\n```\n\nA `COMMITHASH` such as:\n\n```\n7c16d8b1abeced419c14eb9908baeb4229ac0542\n```\n\nAnd (optionally [when branch is enabled](#branch-false)) a `BRANCH` such as:\n\n```\nmaster\n```\n\n## Path Substitutions\n\nIt is also possible to use [path substitutions](https://webpack.js.org/configuration/output/#output-filename) on build to get the revision, version or branch as part of output paths.\n\n- `[git-revision-version]`\n- `[git-revision-hash]`\n- `[git-revision-branch]` (only [when branch is enabled](#branch-false))\n- `[git-revision-last-commit-datetime]`\n\nExample:\n\n```javascript\nmodule.exports = {\n  output: {\n    publicPath: 'http://my-fancy-cdn.com/[git-revision-version]/',\n    filename: '[name]-[git-revision-hash].js',\n  },\n}\n```\n\n## Plugin API\n\nThe `VERSION`, `COMMITHASH`, `LASTCOMMITDATETIME` and `BRANCH` are also exposed through a public API.\n\nExample using the [DefinePlugin](https://webpack.js.org/plugins/define-plugin/#usage):\n\n```javascript\nconst webpack = require('webpack')\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\nconst gitRevisionPlugin = new GitRevisionPlugin()\n\nmodule.exports = {\n  plugins: [\n    gitRevisionPlugin,\n    new webpack.DefinePlugin({\n      VERSION: JSON.stringify(gitRevisionPlugin.version()),\n      COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),\n      BRANCH: JSON.stringify(gitRevisionPlugin.branch()),\n      LASTCOMMITDATETIME: JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),\n    }),\n  ],\n}\n```\n\n## Configuration\n\nThe plugin requires no configuration by default, but it is possible to configure it to support custom git workflows.\n\n### `lightweightTags: false`\n\nIf you need [lightweight tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging#_lightweight_tags) support, you may turn on `lightweightTags` option in this way:\n\n```javascript\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\n\nmodule.exports = {\n  plugins: [\n    new GitRevisionPlugin({\n      lightweightTags: true,\n    }),\n  ],\n}\n```\n\n### `branch: false`\n\nIf you need branch name support, you may turn on `branch` option in this way:\n\n```javascript\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\n\nmodule.exports = {\n  plugins: [\n    new GitRevisionPlugin({\n      branch: true,\n    }),\n  ],\n}\n```\n\n### `commithashCommand: 'rev-parse HEAD'`\n\nTo change the default `git` command used to read the value of `COMMITHASH`.\n\nThis configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.\n\n```javascript\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\n\nmodule.exports = {\n  plugins: [\n    new GitRevisionPlugin({\n      commithashCommand: 'rev-list --max-count=1 --no-merges HEAD',\n    }),\n  ],\n}\n```\n\n### `versionCommand: 'describe --always'`\n\nTo change the default `git` command used to read the value of `VERSION`.\n\nThis configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.\n\n```javascript\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\n\nmodule.exports = {\n  plugins: [\n    new GitRevisionPlugin({\n      versionCommand: 'describe --always --tags --dirty',\n    }),\n  ],\n}\n```\n\n### `branchCommand: 'rev-parse --abbrev-ref HEAD'`\n\nTo change the default `git` command used to read the value of `BRANCH`.\n\nThis configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.\n\n```javascript\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\n\nmodule.exports = {\n  plugins: [\n    new GitRevisionPlugin({\n      branchCommand: 'rev-parse --symbolic-full-name HEAD',\n    }),\n  ],\n}\n```\n\n### `lastCommitDateTimeCommand: 'log -1 --format=%cI'`\n\nTo change the default `git` command used to read the value of `LASTCOMMITDATETIME`.\n\nThis configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.\n\n```javascript\nconst { GitRevisionPlugin } = require('git-revision-webpack-plugin')\n\nmodule.exports = {\n  plugins: [\n    new GitRevisionPlugin({\n      branchCommand: 'log -1 --format=%ci',\n    }),\n  ],\n}\n```\n\n## Outdated webpack\n\nIf your project is not running on Webpack 5, you will need older versions of this package.\n\n### Webpack 4\n\n```\nnpm install git-revision-webpack-plugin@3.0.6\n```\n\n### Webpack 3 or older\n\n```\nnpm install git-revision-webpack-plugin@2.5.1\n```\n\nCheck [issue 29](https://github.com/pirelenito/git-revision-webpack-plugin/issues/29) for more information.\n","funding_links":[],"categories":["Shell","TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirelenito%2Fgit-revision-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpirelenito%2Fgit-revision-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirelenito%2Fgit-revision-webpack-plugin/lists"}