Coder Social home page Coder Social logo

amarant / git-revision-rspack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pirelenito/git-revision-webpack-plugin

0.0 0.0 0.0 769 KB

๐Ÿ— Rspack plugin that generates VERSION and COMMITHASH files during build

Home Page: https://www.npmjs.com/package/git-revision-webpack-plugin

License: MIT License

Shell 47.45% JavaScript 1.83% TypeScript 50.73%

git-revision-rspack-plugin's Introduction

git-revision-rspack-plugin

Simple rspack plugin that generates VERSION and COMMITHASH files during build based on a local git repository.

Usage

Given a rspack project, install it as a local development dependency:

npm install --save-dev @amarant/git-revision-rspack-plugin

Then, simply configure it as a plugin in the rspack config:

const { GitRevisionPlugin } = require('@amarant/git-revision-rspack-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

Plugin API

The VERSION, COMMITHASH, LASTCOMMITDATETIME and BRANCH are also exposed through a public API.

Example using the DefinePlugin:

const rspack = require('@rspack/core')
const { GitRevisionPlugin } = require('@amarant/git-revision-rspack-plugin')
const gitRevisionPlugin = new GitRevisionPlugin()

module.exports = {
  plugins: [
    gitRevisionPlugin,
    new rspack.DefinePlugin({
      VERSION: JSON.stringify(gitRevisionPlugin.version()),
      COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
      BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
      LASTCOMMITDATETIME: JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
    }),
  ],
}

Configuration

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('@amarant/git-revision-rspack-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('@amarant/git-revision-rspack-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('@amarant/git-revision-rspack-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('@amarant/git-revision-rspack-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('@amarant/git-revision-rspack-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('@amarant/git-revision-rspack-plugin')

module.exports = {
  plugins: [
    new GitRevisionPlugin({
      branchCommand: 'log -1 --format=%ci',
    }),
  ],
}

git-revision-rspack-plugin's People

Contributors

pirelenito avatar dependabot[bot] avatar mawi12345 avatar tartineskiller avatar nevon avatar karlhorky avatar simonfyi avatar amarant avatar jansauer avatar seiyria avatar mlandauer avatar robclemons avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.