Skip to content

thecity/git-revision-webpack-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git Revision Webpack Plugin

Build Status npm version js-standard-style Code Climate

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

Usage

Given a webpack project, 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:

var 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

And a COMMITHASH such as:

7c16d8b1abeced419c14eb9908baeb4229ac0542

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

var GitRevisionPlugin = require('git-revision-webpack-plugin')

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

Path Substitutions

It is also possible to use two path substituitions on build to get either the revision or version as part of output paths.

  • [git-revision-version]
  • [git-revision-hash]

Example:

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

Public API

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

Example using the DefinePlugin:

var gitRevisionPlugin = new GitRevisionPlugin()

module.exports = {
  plugins: [
    new DefinePlugin({
      'VERSION': JSON.stringify(gitRevisionPlugin.version()),
      'COMMITHASH': JSON.stringify(gitRevisionPlugin.commithash()),
    })
  ]
}

About

Webpack plugin that generates VERSION and COMMITHASH files during build

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 64.9%
  • JavaScript 35.1%