1.0.6 • Published 6 months ago

@lingxiteam/git-version-webpack-plugin v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

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-plugin

Usage

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

PropertyTypeDefaultDescript
envFunction''Format of environment variables in process.env
fileFunction''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.
DefinePluginFunction''The webpack inner DefinePlugin that output environment variables, by default, are found from the list of plugins currently configured for webpack.config.js
1.0.6

6 months ago

1.0.5

8 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

12 months ago

1.0.1

12 months ago