-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
90 lines (73 loc) · 2.05 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
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
babel = require('gulp-babel'),
browserify = require('browserify'),
watchify = require('watchify'),
buffer = require('vinyl-buffer'),
connect = require('gulp-connect'),
source = require('vinyl-source-stream'),
concat = require('gulp-concat'),
merge = require('merge-stream'),
process = require('process'),
rename = require('gulp-rename'),
runSequence = require('run-sequence')
paths = {
entry: './src/main.js',
dist: './dist/'
};
gulp.task('build_sources', function() {
var app = browserify(paths.entry)
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(babel({
presets: [
["es2015", { "modules": false }]
]
}))
.pipe(uglify())
.pipe(gulp.dest(paths.dist));
return app;
});
gulp.task('build', function(cb) {
runSequence([
'copy_html',
'copy_lib',
'copy_resources',
'build_sources',
], cb);
});
// DEVELOPMENT
gulp.task('watch', function(cb) {
runSequence([
'copy_html',
'copy_lib',
'copy_resources',
'compile_javascript',
], cb);
});
gulp.task('copy_html', function(cb) {
gulp.src("./src/index.html").pipe(gulp.dest(paths.dist))
});
gulp.task('copy_lib', function(cb) {
gulp.src("./src/lib/**/*").pipe(gulp.dest(paths.dist + "/lib"))
});
gulp.task('copy_resources', function(cb) {
gulp.src("./src/assets/**/*").pipe(gulp.dest(paths.dist + "/assets"))
});
gulp.task('compile_javascript', function(cb) {
var bundler = browserify(paths.entry, watchify.args);
var bundle = function() {
console.log("rebuilding app.js")
bundler
.bundle()
.on('error', function (e) {throw e;})
.pipe(source('app.js'))
.pipe(buffer())
.pipe(connect.reload())
.pipe(gulp.dest(paths.dist))
}
watchified = watchify(bundler);
watchified.on('update', bundle);
return bundle();
});