-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_js.js
55 lines (52 loc) · 1.1 KB
/
compile_js.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
50
51
52
53
54
55
var fs = require('fs');
var path = require('path');
var browserify = require('browserify');
var exorcist = require('exorcist');
var b = browserify({
debug: true
});
var program = require('commander');
var input = null;
var output = process.stdout; // default
var outputPath = "";
program
.version('1.0.0')
.arguments('<src> [srcs...]')
.action(function (src, srcs) {
input = [src];
if (srcs && srcs.length > 0) {
input = input.concat(srcs);
}
})
.option('-o, --output <filename>', 'set the output file.')
.parse(process.argv);
if (!input) {
program.help();
}
if (program.output) {
outputPath = path.resolve(program.output);
output = fs.createWriteStream(outputPath);
}
input.forEach(element => {
b.add(element);
});
b.transform("babelify", {
global: true,
presets: ["es2015"],
})
.transform("windowify", {
global: true,
})
.transform("uglifyify", {
global: true,
mangle: {
keep_fnames: true
}
});
if (outputPath != "") {
let bundle = b.bundle()
.pipe(exorcist(outputPath + '.map'))
.pipe(output);
} else {
b.bundle().pipe(output);
}