-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
71 lines (61 loc) · 1.85 KB
/
gulpfile.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
/*jshint node:true*/
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
packageJSON = require('./package.json');
/**
* process all the js file
*/
gulp.task('js', function () {
var config = {
pkg: packageJSON,
banner: '/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.homepage %>\n' +
' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
' * License: <%= pkg.license %>\n' +
' */\n\n\n'
};
return gulp.src('./src/*.js')
/* 1. bundle js */
.pipe(plugins.concat('core.js'))
/* 2. add angular $inject */
.pipe(plugins.ngAnnotate({
add: true,
single_quotes: true
}))
/* 2. add license header */
.pipe(plugins.header(config.banner, {
timestamp: (new Date()).toISOString(),
pkg: config.pkg
}))
.pipe(gulp.dest('./dist'))
.pipe(plugins.bytediff.start())
/* 3. minify */
.pipe(plugins.uglify({
preserveComments: 'license'
}))
.pipe(plugins.bytediff.stop(byteDiffFormatter))
.pipe(plugins.rename({extname: '.min.js'}))
.pipe(gulp.dest('./dist'));
});
gulp.task('default', ['js']);
/**
* Formatter for `bytediff` to display the size changes after processing
* @param data {Object}
* @returns {string}
*/
function byteDiffFormatter(data) {
var difference = (data.savings > 0) ? ' smaller.' : ' larger.';
return data.fileName + ' went from ' +
(data.startSize / 1000).toFixed(2) + ' KB to ' + (data.endSize / 1000).toFixed(2) + ' KB' +
' and is ' + formatPercent(1 - data.percent, 2) + '%' + difference;
}
/**
* Format a number as a percentage
* @param num
* @param precision
* @returns {string}
*/
function formatPercent(num, precision) {
return (num * 100).toFixed(precision);
}