-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (77 loc) · 2 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
90
91
92
93
94
95
96
97
98
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var watchify = require('watchify');
var notify = require('gulp-notify');
var uglify = require('gulp-uglify');
var buffer = require('vinyl-buffer');
var es6ify = require('es6ify');
var fs = require('fs');
var connect = require('gulp-connect');
var rimraf = require('gulp-rimraf');
var watch = require('gulp-watch');
var appDir = './app';
var srcDir = appDir + '/src';
var distDir = appDir + '/dist';
es6ify.traceurOverrides = {
annotations: true,
modules: 'commonjs'
}
function handleErrors () {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end');
}
function buildScript (file, watch, minify) {
var bundler = browserify({ debug: true });
bundler
.add(es6ify.runtime)
.require(require.resolve(srcDir + '/' + file), { entry: true })
.transform(es6ify)
if (watch) {
bundler = watchify(bundler, {})
}
bundler.on('error', handleErrors);
bundler.on('update', rebundle);
function rebundle () {
var stream = bundler.bundle();
gutil.log('Rebundling...');
stream = stream
.on('error', handleErrors)
.pipe(source(file));
if (minify) {
stream = stream
.pipe(buffer())
.pipe(uglify());
}
stream = stream
.pipe(gulp.dest(distDir))
.pipe(connect.reload());
return stream;
}
return rebundle();
}
gulp.task('connect', function () {
return connect.server({
root: ['app'],
port: 8888,
livereload: true
});
});
gulp.task('clean:dist', function () {
return gulp.src(distDir, { read: false })
.pipe(rimraf({ force: true }));
});
gulp.task('build', ['clean:dist'], function () {
return buildScript('main.js', false, true);
});
gulp.task('default', ['clean:dist', 'connect'], function () {
//watch(appDir + '/**/*.html', function () {
// connect.reload();
//});
return buildScript('main.js', true, true);
});