-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
71 lines (49 loc) · 1.4 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
var gulp = require('gulp'),
useref = require('gulp-useref'),
uglify = require('gulp-uglify'),
gulpIf = require('gulp-if'),
cssnano = require('gulp-cssnano'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
del = require('del'),
runSequence = require('run-sequence');
// browserSync = require('browser-sync').create();
// Html task
gulp.task('html' , async function(){
return gulp.src('index.html')
.pipe(gulp.dest('dist'))
});
// Useref task
gulp.task('useref' , async function(){
return gulp.src('index.html')
.pipe(useref())
// Minifies only if it's a JavaScript file
.pipe(gulpIf('*.js',uglify()))
// Minifies only if it's a CSS file
.pipe(gulpIf('*.css' , cssnano()))
.pipe(gulp.dest('dist'))
});
// Imagemin task
gulp.task('images' , async function(){
return gulp.src('./img/*.+(png|jpg|jpeg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('dist/img'))
});
// Cleanning up
gulp.task('clean:dist', function() {
return del.sync('dist');
});
// Run all tasks
gulp.task('build' , async function(done) {
runSequence('clean:dist',
['useref', 'images' , 'html'],
done()
)
});
// Watch task
gulp.task('watch' , function(){
gulp.watch('index.html' , gulp.series('html'));
gulp.watch('index.html' , gulp.series('useref'));
});