-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
91 lines (78 loc) · 2.39 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var browserify = require('gulp-browserify');
var gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var del = require('del');
var runSequence = require('run-sequence');
//--------DEVELOPMENT PROCESS ----------------------
gulp.task('sass',function(){
return gulp.src('app/scss/**/*.scss')
.pipe(sass()) //Using gulp-sass
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({
stream: true
}));
})
gulp.task('cleanJs',function(callback){
return del.sync('app/js/.');
})
gulp.task('browserify', function() {
// Single entry point to browserify
gulp.src('app/sourcejs/**/*.js')
.pipe(browserify({
insertGlobals : true
}))
.pipe(gulp.dest('app/js'))
return browserSync.reload();
});
//--- group task to execute every development task
gulp.task('watch', ['browserSync', 'sass'], function(){
gulp.watch('app/scss/**/*.scss',['sass']);
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/sourcejs/**/*.js', ['browserify']);
// gulp.watch('app/js/**/*.js', browserSync.reload);
//Other watchers
})
gulp.task('browserSync', function(){
browserSync.init({
server: {
baseDir: 'app'
}
})
})
//------------------- END --------------------------
//---------------OPTIMIZATION PROCESS------------------
gulp.task('useref', function(){
return gulp.src('app/*.html')
.pipe(useref())
// Minifies only if it's a JavaScript file
// .pipe(gulpIf('*.js', uglify()))
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'))
})
gulp.task('clean:dist', function(){
return del.sync('dist');
})
gulp.task('data', function(){
return gulp.src('app/data/**/*')
.pipe(gulp.dest('dist/data'))
})
//-------------------- END --------------------------
gulp.task('build',function(callback){
runSequence('clean:dist','sass', 'browserify', 'useref','data', callback)
})
//---- Task to be executed with only gulp command ----
gulp.task('default', function(callback){
runSequence(['sass','browserSync','watch'],callback)
})
gulp.task('serve', function(){
browserSync.init({
server: {
baseDir: 'dist'
}
})
})