-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
97 lines (80 loc) · 2.64 KB
/
bundle.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var gulp = require('gulp');
var jspm = require('jspm');
var fs = require('fs');
var paths = require('../paths');
var shell = require('child-process-promise');
var filesize = require('filesize');
var gzipSize = require('gzip-size');
/**
* Bundle aurelia-framework into one file
*/
gulp.task('bundle', function (done) {
var distFile = 'aurelia.js';
var outputFile = paths.output+ distFile;
var cmd = [
'aurelia-bootstrapper',
'aurelia-http-client',
'aurelia-dependency-injection',
'aurelia-framework',
'aurelia-router',
'npm:core-js',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]',
'github:aurelia/[email protected]'
].join(' + ');
jspm.bundle(cmd,distFile,{inject:true,minify:true}).then(function(){
fs.rename(distFile, outputFile, function(){
showStats(outputFile);
done();
});
});
});
/**
* Bundle application and vendor files.
*/
gulp.task('bundle-app', function (done) {
var distFile = 'app-bundle.js';
var outputFile = paths.output+distFile;
if(fs.existsSync(outputFile)) fs.unlinkSync(outputFile);
var cmd = "**/* - aurelia";
jspm.bundle(cmd,distFile,{inject:true,minify:true}).then(function(){
fs.rename(distFile, outputFile, function(){
showStats(outputFile);
done();
});
});
});
/**
* unbundle the aurelia-framework and use separate files again
*/
gulp.task('unbundle', function (done) {
return shell.exec('jspm unbundle');
});
function showStats(distFile) {
if(!fs.existsSync(distFile)) return null;
var stats = fs.statSync(distFile);
var cssFile = distFile.substr(0,distFile.lastIndexOf("."))+".css";
var cssExists = fs.existsSync(cssFile);
var cssStats;
if(cssExists) cssStats = fs.statSync(cssFile);
console.log("=============== REPORT ================");
if(cssExists) console.log("Javascript Bundle");
console.log("minified and mangled : " + filesize(stats.size));
console.log("gzip: " + filesize(gzipSize.sync(fs.readFileSync(distFile))));
if(cssExists) {
console.log("");
console.log("CSS Bundle");
console.log("minified and mangled : " + filesize(cssStats.size));
console.log("gzip: " + filesize(gzipSize.sync(fs.readFileSync(cssFile))));
}
console.log("=======================================");
}