npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hzzt/git-revision-webpack-plugin

v3.0.8

Published

Fork https://github.com/pirelenito/git-revision-webpack-plugin.git, Add hashLength

Downloads

5

Readme

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

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

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()),
    })
  ]
}

Configuration

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

hashLength

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

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

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.

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

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.

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

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.

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

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

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

Outdated webpack

If your project is not using webpack version 4 or greater, you will need to install an older version of this package:

npm install [email protected]

Check issue 29 for more information.