Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Pull Git version information into Webpack.

License

Notifications You must be signed in to change notification settings

eloquent/git-version-webpack-plugin

Repository files navigation

Git version Webpack plugin

Pull Git version information into Webpack

Current version Build status Test coverage

Usage

Standalone usage

// webpack.config.js

const GitVersionPlugin = require("@eloquent/git-version-webpack-plugin");

module.exports = {
  plugins: [new GitVersionPlugin()],
};
// webpack.config.js

const GitVersionPlugin = require("@eloquent/git-version-webpack-plugin");
const HtmlPlugin = require("html-webpack-plugin");

module.exports = {
  plugins: [new HtmlPlugin(), new GitVersionPlugin()],
};

Note that the order of plugins may be significant. That is, HtmlWebpackPlugin may need to appear before GitVersionPlugin. Although this no longer seems to be true under Webpack 5.

Features

  • Adds a single, concise, human-readable VERSION file to the Webpack output.
  • Integrates with html-webpack-plugin, automatically adding a VERSION variable, accessible on the window object.
  • Watches the Git directory for changes when using webpack-dev-server, so that the version always reflects the current Git tag or branch.

Configuration

The following options can be passed to the plugin constructor:

  • path - The path to use for the version file, relative to the output path. Defaults to VERSION.
  • name - The name to use for the version variable, accessible on the window object. Defaults to VERSION.
  • version - Can be used to manually override the version. Useful in the event that Git is not available.