Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
git-revision-webpack-plugin
Advanced tools
[![npm version](https://badge.fury.io/js/git-revision-webpack-plugin.svg)](https://badge.fury.io/js/git-revision-webpack-plugin) [![downloads](https://img.shields.io/npm/dm/git-revision-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/
The git-revision-webpack-plugin is a Webpack plugin that allows you to embed Git revision information into your build. This can be useful for versioning, debugging, and tracking the state of your codebase at the time of the build.
Embed Git Revision Information
This feature allows you to embed the current Git revision information into your Webpack build. The code sample shows how to include the GitRevisionPlugin in your Webpack configuration.
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin();
module.exports = {
plugins: [
gitRevisionPlugin
]
};
Access Git Information in Code
This feature allows you to access Git information such as the version, commit hash, and branch name directly in your code. The code sample demonstrates how to log this information to the console.
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin();
console.log('Version:', gitRevisionPlugin.version());
console.log('Commit Hash:', gitRevisionPlugin.commithash());
console.log('Branch:', gitRevisionPlugin.branch());
Define Global Constants
This feature allows you to define global constants in your Webpack configuration that hold Git information. The code sample shows how to use the DefinePlugin to create global constants for the version, commit hash, and branch name.
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin();
module.exports = {
plugins: [
new webpack.DefinePlugin({
'VERSION': JSON.stringify(gitRevisionPlugin.version()),
'COMMITHASH': JSON.stringify(gitRevisionPlugin.commithash()),
'BRANCH': JSON.stringify(gitRevisionPlugin.branch())
})
]
};
The webpack-build-info-plugin is a Webpack plugin that provides build information including Git commit hash, branch name, and build timestamp. It is similar to git-revision-webpack-plugin but also includes additional build metadata.
The webpack-git-revision plugin is another alternative that focuses on embedding Git revision information into your Webpack build. It provides similar features to git-revision-webpack-plugin but with a different API.
Simple webpack plugin that generates VERSION
and COMMITHASH
files during build based on a local git repository.
Given a webpack 5 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:
const { 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
It is also possible to use path substitutions on build to get the revision, version or branch as part of output paths.
[git-revision-version]
[git-revision-hash]
[git-revision-branch]
(only when branch is enabled)[git-revision-last-commit-datetime]
Example:
module.exports = {
output: {
publicPath: 'http://my-fancy-cdn.com/[git-revision-version]/',
filename: '[name]-[git-revision-hash].js',
},
}
The VERSION
, COMMITHASH
, LASTCOMMITDATETIME
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()),
LASTCOMMITDATETIME: JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
}),
],
}
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:
const { 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:
const { 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.
const { 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.
const { 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.
const { GitRevisionPlugin } = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
branchCommand: 'rev-parse --symbolic-full-name HEAD',
}),
],
}
lastCommitDateTimeCommand: 'log -1 --format=%cI'
To change the default git
command used to read the value of LASTCOMMITDATETIME
.
This configuration is not not meant to accept arbitrary user input and it is executed by the plugin without any sanitization.
const { GitRevisionPlugin } = require('git-revision-webpack-plugin')
module.exports = {
plugins: [
new GitRevisionPlugin({
branchCommand: 'log -1 --format=%ci',
}),
],
}
If your project is not running on Webpack 5, you will need older versions of this package.
npm install git-revision-webpack-plugin@3.0.6
npm install git-revision-webpack-plugin@2.5.1
Check issue 29 for more information.
FAQs
[![npm version](https://badge.fury.io/js/git-revision-webpack-plugin.svg)](https://badge.fury.io/js/git-revision-webpack-plugin) [![downloads](https://img.shields.io/npm/dm/git-revision-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/
The npm package git-revision-webpack-plugin receives a total of 129,382 weekly downloads. As such, git-revision-webpack-plugin popularity was classified as popular.
We found that git-revision-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.