11

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?

2 Answers 2

24

You can get git revision in webpack in this way:

var childProcess = require('child_process'), VERSION = childProcess.execSync('git rev-parse HEAD').toString(); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Remove the carriage return: append .trim() .
3

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.