• Stars
    star
    352
  • Rank 120,622 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🏗 Webpack plugin that generates VERSION and COMMITHASH files during build

git-revision-webpack-plugin

npm version downloads Code Climate

Simple webpack plugin that generates VERSION and COMMITHASH files during build based on a local git repository.

Usage

Given a webpack 5 project (check below for old webpack versions), install it as a local development dependency:

npm install --save-dev git-revision-webpack-plugin

Then, simply configure it as a plugin in the webpack config:

const { GitRevisionPlugin } = require('git-revision-webpack-plugin')

module.exports = {
  plugins: [new GitRevisionPlugin()],
}

It outputs a VERSION based on git-describe such as:

v0.0.0-34-g7c16d8b

A COMMITHASH such as:

7c16d8b1abeced419c14eb9908baeb4229ac0542

And (optionally when branch is enabled) a BRANCH such as:

master

Path Substitutions

It is also possible to use path substitutions on build to get the revision, version or branch as part of output paths.

  • [git-revision-version]
  • [git-revision-hash]
  • [git-revision-branch] (only when branch is enabled)
  • [git-revision-last-commit-datetime]

Example:

module.exports = {
  output: {
    publicPath: 'http://my-fancy-cdn.com/[git-revision-version]/',
    filename: '[name]-[git-revision-hash].js',
  },
}

Plugin API

The VERSION, COMMITHASH, LASTCOMMITDATETIME and BRANCH are also exposed through a public API.

Example using the DefinePlugin:

const webpack = require('webpack')
const { GitRevisionPlugin } = require('git-revision-webpack-plugin')
const gitRevisionPlugin = new GitRevisionPlugin()

module.exports = {
  plugins: [
    gitRevisionPlugin,
    new webpack.DefinePlugin({
      VERSION: JSON.stringify(gitRevisionPlugin.version()),
      COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
      BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
      LASTCOMMITDATETIME: JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
    }),
  ],
}

Configuration

The plugin requires no configuration by default, but it is possible to configure it to support custom git workflows.

lightweightTags: false

If you need lightweight tags support, you may turn on lightweightTags option in this way:

const { GitRevisionPlugin } = require('git-revision-webpack-plugin')

module.exports = {
  plugins: [
    new GitRevisionPlugin({
      lightweightTags: true,
    }),
  ],
}

branch: false

If you need branch name support, you may turn on branch option in this way:

const { GitRevisionPlugin } = require('git-revision-webpack-plugin')

module.exports = {
  plugins: [
    new GitRevisionPlugin({
      branch: true,
    }),
  ],
}

commithashCommand: 'rev-parse HEAD'

To change the default git command used to read the value of COMMITHASH.

This configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.

const { GitRevisionPlugin } = require('git-revision-webpack-plugin')

module.exports = {
  plugins: [
    new GitRevisionPlugin({
      commithashCommand: 'rev-list --max-count=1 --no-merges HEAD',
    }),
  ],
}

versionCommand: 'describe --always'

To change the default git command used to read the value of VERSION.

This configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.

const { GitRevisionPlugin } = require('git-revision-webpack-plugin')

module.exports = {
  plugins: [
    new GitRevisionPlugin({
      versionCommand: 'describe --always --tags --dirty',
    }),
  ],
}

branchCommand: 'rev-parse --abbrev-ref HEAD'

To change the default git command used to read the value of BRANCH.

This configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.

const { GitRevisionPlugin } = require('git-revision-webpack-plugin')

module.exports = {
  plugins: [
    new GitRevisionPlugin({
      branchCommand: 'rev-parse --symbolic-full-name HEAD',
    }),
  ],
}

lastCommitDateTimeCommand: 'log -1 --format=%cI'

To change the default git command used to read the value of LASTCOMMITDATETIME.

This configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.

const { GitRevisionPlugin } = require('git-revision-webpack-plugin')

module.exports = {
  plugins: [
    new GitRevisionPlugin({
      branchCommand: 'log -1 --format=%ci',
    }),
  ],
}

Outdated webpack

If your project is not running on Webpack 5, you will need older versions of this package.

Webpack 4

npm install [email protected]

Webpack 3 or older

npm install [email protected]

Check issue 29 for more information.

More Repositories

1

generator-react-webpack-component

A Yeoman generator to create small and reusable React components using webpack as the build tool.
JavaScript
43
star
2

react-transition

React Component to perform transitions on prop changes
JavaScript
35
star
3

react-controlled-focus

React component for declarative focus
JavaScript
18
star
4

jasmine-testing-example

Sample code files for the Jasmine JavaScript Testing book
JavaScript
9
star
5

git-x

A simple bash script to run git commands into multiple nested git repositories.
Shell
8
star
6

nodejs-in-production

Get the foundation to develop Node.js applications and the tools to put them into production
Ruby
8
star
7

lumine

📷 A stateless photo library service to run on your NAS.
TypeScript
7
star
8

unbubble

📺 Finding meaning through chaos
JavaScript
7
star
9

revelar

Create stunning presentations in Markdown from the confort of your command line
CSS
6
star
10

jasmine-standalone-webpack

Jasmine Standalone Release ported to use webpack
JavaScript
5
star
11

MovieGL

Java OpenGL movie playback
Java
5
star
12

coreos-digital-ocean-hello-world

Very simple provisioning of a machine running CoreOS with a Hello World Docker Container
Shell
4
star
13

backbone-getsome

Simple BackboneJS plugin to create dynamic custom Model attributes
JavaScript
4
star
14

jasmine-standalone-requirejs

This is basicaly the Jasmine Standalone Release ported to use RequireJS.
JavaScript
4
star
15

backbone-accessorize

Simple BackboneJS plugin to automagically create attribute assessors for your model attributes.
JavaScript
3
star
16

bovespa_historical

Parser for the Bovespa Historical files.
Ruby
3
star
17

react-marquee-renderer

🚀 Custom React renderer that supports only marquee tags
TypeScript
3
star
18

makeabandtome

Quick little fun project to generate bands!
Ruby
2
star
19

ecsy-talk

TypeScript
2
star
20

trum

🥁 Web tool to practice drumming
TypeScript
2
star
21

simplest-webpack-example

Just a simple example to show how easy it is to configure webpack
JavaScript
2
star
22

risos

📓 The simplest feed-based RSS feed reader
JavaScript
2
star
23

backbone_coffeescript_simple_use_cases

Very simple backbone use cases demonstrated with Coffeescript
JavaScript
1
star
24

trappist-1

TRAPPIST-1 system rendered in scale 🚀
JavaScript
1
star
25

revelar-app

Mac application to craft presentations in Markdown
JavaScript
1
star
26

react-server-side-rendering-example

Simple POC to test React server side rendering capabilities and code sharing
JavaScript
1
star
27

twinance

Sotck charts + related tweets
Ruby
1
star
28

gonp

A Simple Android game project
Java
1
star
29

clipmeme

Ruby
1
star
30

jquery_form_mapper

A handy jQuery plugin to read all inputs of a form's as a Javascript Object that has the same "structure" as the Rails domain.
JavaScript
1
star
31

jquery.squirrel-scroll

Simple follow scroll implementation that just works
JavaScript
1
star