-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
72 lines (62 loc) · 1.76 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
var gulp = require("gulp");
var browserify = require("browserify");
var watchify = require("watchify");
var underscorify = require("node-underscorify");
var source = require("vinyl-source-stream");
var gutil = require("gulp-util");
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var path = require('path');
var babel = require('gulp-babel');
var sourcemaps = require('gulp-sourcemaps');
var babelify = require('babelify');
//Server
var paths = {
es6: ['es6server/**/*.js'],
es5: 'es5server',
sourceRoot: path.join(__dirname, 'es6server')
};
gulp.task('es6to5server', function (){
return gulp.src(paths.es6)
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.', {sourceRoot: paths.sourceRoot}))
.pipe(gulp.dest(paths.es5));
});
//Client
gulp.task('build:js', function(){
return browserify({
entries: './browserify/index.js',
debug: true,
})
.transform(underscorify.transform())
.transform(babelify)
.bundle()
.on("error", gutil.log.bind(gutil, 'Browserify Error'))
.on("log", gutil.log)
.pipe(source("app.js"))
.pipe(buffer())
.pipe(gulp.dest("./public/js"));
});
gulp.task('watch', function (){
gulp.watch(paths.es6, ['es6to5server']);
gulp.watch(['browserify/**/*.js'], ['build:js']);
});
gulp.task('default', ['watch']);
/*
Build Client for Prod
*/
var browserifyProd = browserify("./browserify/index.js");
browserifyProd.transform(underscorify.transform());
browserifyProd.transform(babelify);
browserifyProd.on("update", buildProd);
browserifyProd.on("log", gutil.log);
function buildProd() {
return browserifyProd.bundle()
.on("error", gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source("app.js"))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest("./public/js"));
}
gulp.task("build:js:prod", buildProd);