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?
bolelamx
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
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
来源:https://stackoverflow.com/questions/35150186/getting-git-revision-hash-with-webpack