Have ideas to improve npm?Join in the discussion! »

git-rev-webpack-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

git-rev-webpack-plugin

NPM version Build Status Maintainability Test Coverage

Webpack plugin for using git branch, hash (from the last commit) and tag as substitutions in output.filename and output.chunkFilename.

Getting Started

Install it

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

Add the plugin to your webpack config. For example:

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:

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.

License

MIT

Install

npm i git-rev-webpack-plugin

DownloadsWeekly Downloads

221

Version

0.3.1

License

MIT

Unpacked Size

21.3 kB

Total Files

17

Last publish

Collaborators

  • avatar