Crotery / git-revision-webpack-plugin

πŸ— Webpack plugin that generates VERSION and COMMITHASH files during build

Home Page:https://www.npmjs.com/package/git-revision-webpack-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Git Revision Webpack Plugin

Build Status npm version downloads 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

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 substituitions on build to get the revision, version or branch as part of output paths.

Example:

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

Plugin API

The VERSION, COMMITHASH and BRANCH 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()),
      'BRANCH': JSON.stringify(gitRevisionPlugin.branch()),
    })
  ]
}

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:

var 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:

var 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:

var 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:

var 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:

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

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

About

πŸ— Webpack plugin that generates VERSION and COMMITHASH files during build

https://www.npmjs.com/package/git-revision-webpack-plugin

License:MIT License


Languages

Language:Shell 51.0%Language:JavaScript 49.0%