forked from Matt-Esch/virtual-dom
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
executable file
·89 lines (82 loc) · 2.07 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var gulp = require('gulp')
, map = require('map-stream')
, maxmin = require('maxmin')
, uglify = require('gulp-uglify')
, webpack = require('gulp-webpack')
, config = require('./webpack.config');
function Size(name) {
this._name = name;
this._max = undefined;
this._min = undefined;
}
Size.prototype.max = function () {
var self = this;
return map(function (file, cb) {
self._max = file.contents;
cb(null, file);
});
};
Size.prototype.min = function (rename) {
var self = this;
return map(function (file, cb) {
self._min = file.contents;
rename &&
(file.path = rename(file.path));
cb(null, file);
});
};
Size.prototype.print = function () {
var self = this;
setTimeout(function () {
console.log(self._name, maxmin(self._max, self._min, true));
}, 0);
}
var size = new Size('vd.js')
, allSize = new Size('all.js');
gulp.task('vd-build', function (done) {
gulp.src(['vd.js'])
.pipe(webpack(config.vd))
.pipe(size.max())
.pipe(gulp.dest('./dist'))
.on('end', function () {
done();
});
});
gulp.task('vd-uglify', ['vd-build'], function (done) {
gulp.src(['dist/vd.js'])
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(size.min(function (path) {
return path.replace(/\.js$/, '.min.js');
}))
.pipe(gulp.dest('./dist'))
.on('end', function () {
size.print();
done();
})
});
gulp.task('all-build', function (done) {
gulp.src(['index.js'])
.pipe(webpack(config.all))
.pipe(allSize.max())
.pipe(gulp.dest('./dist'))
.on('end', function () {
done();
});
});
gulp.task('all-uglify', ['all-build'], function (done) {
gulp.src(['dist/all.js'])
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(allSize.min(function (path) {
return path.replace(/\.js$/, '.min.js');
}))
.pipe(gulp.dest('./dist'))
.on('end', function () {
allSize.print();
done();
})
});
gulp.task('default', ['vd-uglify', 'all-uglify']);