forked from SW999/todo-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
72 lines (64 loc) · 1.82 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 browserify = require('browserify'),
watchify = require('watchify'),
gulp = require('gulp'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
sass = require('gulp-sass'),
plumber = require('gulp-plumber'),
source = require('vinyl-source-stream');
//**************** Server ***************************
gulp.task('browser-sync', function () {
browserSync({
server: {
baseDir: "./"
}
});
});
//**************** Build/Watch SASS *****************************
function buildSass() {
return gulp.src('scss/*.scss')
.pipe(plumber())
.pipe(sass())
.pipe(gulp.dest('css'))
.pipe(reload({stream: true}));
}
gulp.task('build:sass', buildSass);
gulp.task('watch:sass', function () {
buildSass();
gulp.watch('scss/**/*.scss', buildSass);
});
// //**************** Build/Watch JS *******************************
//browserify bundler is wrapped in watchify so that it can do fast rebuilds from cache
var buildBundler = watchify(browserify('./js/app.js', {
// Required watchify args
cache: {},
packageCache: {},
fullPaths: true
}));
function buildJS() {
return buildBundler
.bundle()
.on('error', function (err) {
console.log(err.message);
// this.end();
})
.pipe(source('build.js'))
.pipe(gulp.dest('./js'))
.pipe(reload({stream: true}));
}
gulp.task('build:js', buildJS);
gulp.task('watch:js', function () {
buildJS();
buildBundler.on('update', function () {
console.log('Rebuilding JS (from cache)');
buildJS();
})
});
// //**************** HTML *****************************
gulp.task('watch:html', function () {
gulp.watch('./index.html', function () {
reload({stream: true});
});
});
//**************** Main Dev Tasks ***********************
gulp.task('default', ['browser-sync', 'watch:sass', 'watch:js', 'watch:html']);