-
Notifications
You must be signed in to change notification settings - Fork 5
/
js
63 lines (52 loc) · 1.32 KB
/
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
56
57
58
59
60
61
62
63
#!/usr/bin/env node
var
fs = require('fs-extra'),
inFile = 'src/js/bootstrap.js',
outFile = 'dist/public/js/bundle.js'
;
try {
js();
} catch (e) {
console.log(e);
}
function js() {
browserify(inFile)
.then(minify)
.then(save)
.catch(function(err) {
console.log(err);
})
;
}
function browserify(inFile) {
return new Promise(function(resolve, reject) {
console.log('Browserify ' + inFile);
var browserify = require('browserify');
browserify(inFile)
.transform('reactify', {es6: true, harmony: true})
.bundle(function(err, buff) {
if (err)
reject(err);
else
resolve(buff.toString());
})
;
});
}
function minify(codeString) {
return new Promise(function(resolve, reject) {
console.log('Uglify...');
var UglifyJS = require('uglify-js');
var unminifiedCodeSize = codeString.length;
console.log('Unminified code size: ' + unminifiedCodeSize + ' characters');
var result = UglifyJS.minify(codeString, {fromString: true});
var minifiedCode = result.code;
var minifiedCodeSize = minifiedCode.length;
console.log('minififed code size: ' + minifiedCodeSize + ' characters, ' + Math.round(minifiedCodeSize / unminifiedCodeSize * 100) + '%');
resolve(minifiedCode);
});
}
function save(codeString) {
console.log('Saving ' + outFile);
fs.outputFileSync(outFile, codeString);
}