Pull Git version information into Webpack
// webpack.config.js
const GitVersionPlugin = require("@eloquent/git-version-webpack-plugin");
module.exports = {
plugins: [new GitVersionPlugin()],
};
Usage with html-webpack-plugin
// 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.
- Adds a single, concise, human-readable
VERSION
file to the Webpack output. - Integrates with html-webpack-plugin, automatically adding a
VERSION
variable, accessible on thewindow
object. - Watches the Git directory for changes when using webpack-dev-server, so that the version always reflects the current Git tag or branch.
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 toVERSION
.name
- The name to use for the version variable, accessible on thewindow
object. Defaults toVERSION
.version
- Can be used to manually override the version. Useful in the event that Git is not available.