-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (61 loc) · 1.84 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
const gulp =require('gulp');
const sass =require('gulp-sass');
const cssnano = require('gulp-cssnano');
const rev =require('gulp-rev');
const uglify = require('gulp-uglify-es').default;
const imagemin = require('gulp-imagemin');
const del = require('del');
gulp.task('css',function(done){
console.log('minifying css');
//minification
gulp.src('./assests/sass/**/*.scss')
.pipe(sass()) //pipe calls all the sub middlewares in gulp
.pipe(cssnano())
.pipe(gulp.dest('./assests.css'));
// after minification changing file name convention form home.css to home-94jkj34j.css
gulp.src('./assests/**/*.css')
.pipe(rev())
.pipe(gulp.dest('./public/assests'))
.pipe(rev.manifest({
cwd : 'public' ,
merge : true
}))
.pipe(gulp.dest('./public/assests'));
done();
})
gulp.task('js', function(done){
console.log('minifying js...');
gulp.src('./assests/**/*.js')
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('./public/assests'))
.pipe(rev.manifest({
cwd: 'public',
merge: true
}))
.pipe(gulp.dest('./public/assests'));
done()
});
gulp.task('images', function(done){
console.log('compressing images...');
gulp.src('./assests/**/*.+(png|jpg|gif|svg|jpeg)')
.pipe(imagemin())
.pipe(rev())
.pipe(gulp.dest('./public/assests'))
.pipe(rev.manifest({
cwd: 'public',
merge: true
}))
.pipe(gulp.dest('./public/assests'));
done();
});
// empty the public/assets directory
gulp.task('clean:assests', function(done){
del.sync('./public/assests');
done();
});
//to run all the 4 tasks('clean:assests', 'css', 'js', 'images') in one command ("gulp build")
gulp.task('build', gulp.series('clean:assests', 'css', 'js', 'images'), function(done){
console.log('Building assets');
done();
});