-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.shell.plugin.js
42 lines (34 loc) · 1 KB
/
webpack.shell.plugin.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
35
36
37
38
39
40
41
42
'use strict';
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
console.log(stdout);
}
function WebpackShellPlugin(options) {
var defaultOptions = {
onBuildStart: [],
onBuildEnd: []
};
this.options = Object.assign(defaultOptions, options);
}
WebpackShellPlugin.prototype.apply = function (compiler) {
const options = this.options;
compiler.plugin("watch-run", (watching, cb) => {
if (options.onBuildStart.length) {
console.log("Executing pre-build scripts");
options.onBuildStart.forEach(async script => await exec(script, (error, stdout, stderr) => {
puts(error, stdout, stderr);
console.log("Pre-build done");
cb();
}));
//cb();
}
});
compiler.plugin("emit", (compilation, callback) => {
if (options.onBuildEnd.length) {
console.log("Executing post-build scripts");
options.onBuildEnd.forEach(script => exec(script, puts));
}
callback();
});
};
module.exports = WebpackShellPlugin;