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?
You can get git revision in webpack in this way:
var childProcess = require('child_process'),
VERSION = childProcess.execSync('git rev-parse HEAD').toString();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With