Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting git-revision hash with webpack

I'm trying to create archive with webpack with suffix by git-revision. Could you tell me please what is good way to do it?

like image 790
Stepan Suvorov Avatar asked Feb 02 '16 09:02

Stepan Suvorov


2 Answers

You can get git revision in webpack in this way:

var childProcess = require('child_process'),
VERSION = childProcess.execSync('git rev-parse HEAD').toString();
like image 59
bolelamx Avatar answered Sep 28 '22 04:09

bolelamx


You can combine git-rev, arciverjs and on-build-webpack plugins for these purposes

https://www.npmjs.com/package/git-rev

http://archiverjs.com/docs/

https://www.npmjs.com/package/on-build-webpack

var childProcess = require('child_process'),
    VERSION = childProcess.execSync('git rev-parse HEAD').toString();

var WebpackOnBuildPlugin = require('on-build-webpack');

var plugins = [
  //...
  new WebpackOnBuildPlugin(function(stats) {
    var fs = require('fs');
    var archiver = require('archiver');

    var output = fs.createWriteStream(__dirname + '/' + VERSION + '-example.tar');
    var archive = archiver('tar');

    output.on('close', function() {
      console.log(archive.pointer() + ' total bytes');
      console.log('archiver has been finalized and the output file descriptor has closed.');
    });

    archive.on('error', function(err) {
      throw err;
    });

    archive.pipe(output);

    archive.bulk([
      { expand: true, cwd: 'source-dir/', src: ['*.*'] }
    ]);

    archive.finalize();
  })
];

Here is the code snippet from webpack config file which will create an archive with revision in name. For getting git revision you can use git-rev plugin or code snippet from answer of @bolelamx

like image 32
Edward Avatar answered Sep 28 '22 04:09

Edward