https://github.com/gilbarbara/git-rev-webpack-plugin
Webpack plugin to use git branch, hash and tag as substitutions for file names
https://github.com/gilbarbara/git-rev-webpack-plugin
Last synced: 4 months ago
JSON representation
Webpack plugin to use git branch, hash and tag as substitutions for file names
- Host: GitHub
- URL: https://github.com/gilbarbara/git-rev-webpack-plugin
- Owner: gilbarbara
- License: mit
- Created: 2019-07-25T15:20:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-09T19:48:45.000Z (about 5 years ago)
- Last Synced: 2025-03-24T07:51:03.214Z (10 months ago)
- Language: Shell
- Size: 342 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# git-rev-webpack-plugin
[](https://www.npmjs.com/package/git-rev-webpack-plugin) [](https://travis-ci.com/gilbarbara/git-rev-webpack-plugin) [](https://codeclimate.com/github/gilbarbara/git-rev-webpack-plugin/maintainability) [](https://codeclimate.com/github/gilbarbara/git-rev-webpack-plugin/test_coverage)
[Webpack](http://webpack.github.io/) plugin for using git branch, hash (from the last commit) and tag as substitutions in output.filename and output.chunkFilename.
## Getting Started
Install it
```bash
npm install --save-dev git-rev-webpack-plugin
```
Add the plugin to your `webpack` config. For example:
```js
const GitRevPlugin = require('git-rev-webpack-plugin');
module.exports = {
plugins: [
new GitRevPlugin(),
],
output: {
filename: '[name]-[git-branch]-[git-tag]-[git-hash].js',
},
};
```
Alternatively you can save the instance to re-use it:
```js
const GitRevPlugin = require('git-rev-webpack-plugin');
const gitRevPlugin = new GitRevPlugin();
module.exports = {
plugins: [
gitRevPlugin,
new webpack.DefinePlugin({
GITHASH: JSON.stringify(gitRevPlugin.hash()),
}),
],
};
```
## Options
You can customize the commands and the path.
- `branchCommand`: The git command to get the branch.
Defaults to: `rev-parse --abbrev-ref HEAD`
- `hashCommand`: The git command to get the commit short hash.
Defaults to: `rev-parse --short HEAD`
- `tagCommand`: The git command to get the latest tag.
Defaults to: `describe --abbrev=0 —tags`
- `path`: The path to the project if not the current cwd.
## API
- `branch()`: Get the branch
- `hash(long)`: Get the hash
- `tag()`: Get the tag
## Credits
This is based on [git-revision-webpack-plugin](https://github.com/pirelenito/git-revision-webpack-plugin).
## License
MIT