-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
92 lines (79 loc) · 2.28 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
92
var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync');
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var runSequence = require('run-sequence');
//Basic Gulp task syntax
/*gulp.task('testing', function () {
console.log('Testing, testing, 1, 2, 3');
});*/
//Development Tasks
//-----------------
//Start browserSync server
gulp.task('browserSync', function () {
browserSync({
server: {
baseDir: 'app'
},
})
});
gulp.task('sass', function () {
return gulp.src('app/scss/**/*.scss')
.pipe(sass()) //Converts Sass to CSS with gulp-sass
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({
stream: true
}));
})
//Watchers
gulp.task('watch', ['browserSync', 'sass'], function () {
gulp.watch('app/scss/**/*.scss', ['sass']);
// Reloads the browser whenever HTML or JS files change
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/js/**/*.js', browserSync.reload);
})
//Optimization Tasks
// -----------------
//Optimizing CSS and Javascript
//concatenates CSS and JS files into a single file
gulp.task('useref', function () {
return gulp.src('app/*.html')
.pipe(useref())
// Minifies only if it's a JS file
.pipe(gulpIf('*.js', uglify()))
// Minifies only if it's a CSS file
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'));
});
//Optimizing Images
gulp.task('images', function () {
return gulp.src('app/images/**/*.+(png|jpg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
});
//Cleaning
//Cleaning up generated files automatically(ie deleting them)
/*gulp.task('clean:dist', function () {
return del.sync('dist')
});*/
//Build Sequences
//---------------
gulp.task('default', function (callback) {
runSequence(['sass', 'browserSync', 'watch'],
callback
)
})
gulp.task('build', function (callback) {
runSequence(
'clean:dist', ['sass', 'useref', 'images'],
callback
)
})