forked from ginozhan/webpack-deploy2war
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 848 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var fs = require('fs');
var archiver = require('archiver');
function DeployToWar(options) {
this.options = options || {};
this.fileName = options.fileName || 'project.zip';
this.distFolder = options.distFolder || 'dist';
}
DeployToWar.prototype.apply = function (compiler) {
var self = this;
var options = compiler.options;
compiler.plugin('done', function () {
if (!fs.existsSync(self.distFolder)) {
return;
}
var dir = require('path').dirname(self.fileName);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
var output = fs.createWriteStream(self.fileName);
var archive = archiver('zip');
archive.pipe(output);
archive.directory(self.distFolder, '/')
archive.finalize();
});
};
module.exports = DeployToWar;