-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (68 loc) · 1.99 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
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 gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var fontmin = require('gulp-fontmin');
//TASK TO CREATE AND OPTIMIZE THE JS, CSS, HTML FILES
gulp.task('useref', function() {
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpIf('*.js', uglify()))
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dest'))
});
//TASK TO RELOAD AUTOMATICALLY
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: 'app'
},
})
})
//TASK FOR SASS TO CSS
gulp.task('sass', function() {
return gulp.src('app/scss/**/*.scss') // Gets all files ending with .scss in app/scss and children dirs
.pipe(sass())
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({
stream: true
}))
})
//TASK TO WATCH SASS AND RELOAD
gulp.task('watch', ['browserSync', 'sass'], function() {
gulp.watch('app/scss/**/*.scss', ['sass']);
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/js/**/*.js', browserSync.reload);
})
//TASK TO OPTIMIZE IMAGES
gulp.task('images', function() {
return gulp.src('app/images/**/*.+(png|jpg|gif|svg)')
.pipe(imagemin())
.pipe(gulp.dest('dest/images'))
});
//TASK TO MINIFY FONTS
function minifyFont(text, cb) {
gulp
.src('app/fonts/*.ttf')
.pipe(fontmin({
text: text
}))
.pipe(gulp.dest('dest/fonts'))
.on('end', cb);
}
gulp.task('fonts', function(cb) {
var buffers = [];
gulp
.src('index.html')
.on('data', function(file) {
buffers.push(file.contents);
})
.on('end', function() {
var text = Buffer.concat(buffers).toString('utf-8');
minifyFont(text, cb);
});
});