@lingxiteam/git-version-webpack-plugin
v1.0.6
Published
a webpack plugin which is used to output git information for the current repository
Downloads
22
Maintainers
Keywords
Readme
git-version-webpack-plugin
This plugin is used to output git information for the current repository through the .git directory, regardless of whether GIT is installed in the current environment
Install
$ npm install -D @lingxiteam/git-version-webpack-plugin
or
$ yarn add -D @lingxiteam/git-version-webpack-pluginUsage
The plugin will generate a json or yaml(yml) file for you, along with an environment variable for process.env that contains the current GIT information. Just add the plugin to your webpack
config as follows:
webpack.config.js
const GitVersionWebpackPlugin = require('@lingxiteam/git-version-webpack-plugin');
module.exports = {
entry: 'index.js',
output: {
path: __dirname + '/dist',
filename: 'index_bundle.js'
},
plugins: [
new GitVersionWebpackPlugin({
env: (gitInfo) => gitInfo,
file: (gitInfo) => ({name: 'gitInfo.json', content: gitInfo })
})
]
}This will generate a file dist/gitInfo.json and environment variable information for process.env
The json file containing the following:
{
"branchName": "master",
"commitId": "bc7ec81d3f58b9b0e38a31af2fefb77535d0bc7d",
"author": "xxx",
"time": "2023/5/16 13:54:33",
"timestamp": "1684721536"
}The usage for environment variable in the code:
console.log('branchName', process.env.branchName)Options
| Property | Type | Default | Descript |
| --- | --- | --- | --- |
| env | Function | '' | Format of environment variables in process.env |
| file | Function | '' | Allow to output files in json or yaml format. The name field of the outgoing argument determines the output of the json or yaml format file while the content field determines the content of the file. |
| DefinePlugin | Function | '' | The webpack inner DefinePlugin that output environment variables, by default, are found from the list of plugins currently configured for webpack.config.js |
