-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (80 loc) · 2.48 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
93
94
// gulp.task('css', function(done){
// console.log('minifying css...');
// gulp.src('./assets/scss/**/*.scss')
// .pipe(sass())
// .pipe(minifyCSS())
// // .pipe(cssnano())
// .pipe(gulp.dest('./assets-minicss'));
// gulp.src('./assets-minicss/**/*.css')
// .pipe(rev())
// .pipe(gulp.dest('./public/assets/css'))
// .pipe(rev.manifest({
// cwd: 'public',
// merge: true
// }))
// .pipe(gulp.dest('./public/assets'));
// done();
// });
// const cssnano = require('gulp-cssnano');
// const minifyCSS = require('gulp-csso');
const gulp = require('gulp');
const sass = require('gulp-sass');
const minifyCSS = require('gulp-clean-css');
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('css minifying');
gulp.src('./assets/scss/**/*.scss')
.pipe(sass())
.pipe(minifyCSS())
.pipe(gulp.dest('./assets/css'));
gulp.src('./assets/**/*.css')
.pipe(rev())
.pipe(gulp.dest('./public/assets')) // write rev'd assets to build dir
.pipe(rev.manifest({
base:'./public/assets',
merge:true
}))
.pipe(gulp.dest('./public/assets'));
done();
})
gulp.task('js', function(done){
console.log('minifying js...');
gulp.src('./assets/**/*.js')
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('./public/assets')) // write rev'd assets to build dir
.pipe(rev.manifest({
base:'./public/assets',
merge:true
}))
.pipe(gulp.dest('./public/assets'))
done();
});
gulp.task('images', function(done){
console.log('compressing images...');
gulp.src('./assets/**/*.+(png|jpg|gif|svg|jpeg)')
.pipe(imagemin())
// .pipe(gulp.dest('./public/assets'))
.pipe(rev())
.pipe(gulp.dest('./public/assets')) // write rev'd assets to build dir
.pipe(rev.manifest({
base:'./public/assets',
merge:true
}))
.pipe(gulp.dest('./public/assets'));
done();
});
// empty the public/assets directory
gulp.task('clean:assets', function(done){
del.sync('./public');
del.sync('./rev-manifest.json');
//this will delete the manifest every time gulp build runs ,so may solve your problem of manifest adding,deleting,etc.
done();
});
gulp.task('build', gulp.series('clean:assets' , 'images' , 'css' , 'js'), function(done){
console.log('Building assets');
done();
});