-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
76 lines (58 loc) · 1.77 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var rimraf = require('rimraf');
var jsonServer = require('json-server');
var apiServer = jsonServer.create();
var router = jsonServer.router('db.json');
var serve = require('gulp-serve');
var sass = require('gulp-sass');
/****************************************
JS
*****************************************/
var bundler = browserify({
entries: ['./src/app.js'],
debug: true
});
bundler.on('log', gutil.log); // output build logs to terminal
gulp.task('clean', function (cb) {
rimraf('build', cb);
});
gulp.task('build', ['clean'], function () {
return bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
.pipe(gulp.dest('build'));
});
/****************************************
Servers (Web and API)
*****************************************/
apiServer.use(jsonServer.defaults);
apiServer.use(router);
gulp.task('serve:api', function (cb) {
apiServer.listen(3000, cb);
});
gulp.task('serve:web', ['serve:api'], serve({
root: ['.'],
port: process.env.PORT || 8000
}));
gulp.task('serve', ['serve:api', 'serve:web']);
/****************************************
Sass
*****************************************/
gulp.task('sass', function() {
return gulp.src('./sass/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
/****************************************
Watch
*****************************************/
gulp.task('watch', ['build'], function () {
gulp.watch(['src/**/*.js', 'src/**/*.hbs'], ['build']);
gulp.watch('./sass/*.scss', ['sass'])
})
// Default
gulp.task('default', ['serve', 'watch', 'sass']);