forked from KyberNetwork/KyberSwap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-shell-plugin.js
49 lines (39 loc) · 1.25 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
43
44
45
46
47
48
49
'use strict';
const exec = require('child_process').exec;
function puts(error, stdout, stderr) {
console.log(stdout);
}
class WebpackShellPlugin {
constructor(options) {
let defaultOptions = {
onBuildStart: [],
onBuildEnd: []
};
this.options = Object.assign(defaultOptions, options);
}
apply (compiler) {
const options = this.options;
compiler.plugin("compilation", compilation => {
if(options.onBuildStart.length){
console.log("Executing pre-build scripts");
options.onBuildStart.forEach(script => exec(script, puts));
}
});
compiler.plugin("emit", (compilation, callback) => {
if(options.onBuildEnd.length){
options.onBuildEnd.forEach(script => {
let newScript = script.replace(/\[(.+?)\]/g, i => {
let param = i.replace('[','').replace(']','')
return compilation[param] || options[param]
// return options[param]
})
console.log("$$$$$$$$$ new script $$$$$$$$$$", newScript)
return exec(newScript, puts)
});
// options.onBuildEnd.forEach(script => exec(script, puts));
}
callback();
});
};
}
module.exports = WebpackShellPlugin;