forked from yogiprsetya/frontend-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
100 lines (87 loc) · 2.77 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
95
96
97
98
99
100
// Konfigurasi
var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var merge = require('merge-stream');
var clean = require('gulp-clean');
var cssnano = require('gulp-cssnano');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var htmlmin = require('gulp-htmlmin');
var zip = require('gulp-zip');
var gutil = require('gulp-util');
var clean = require('gulp-clean');
gulp.task('sass', function(){
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src('./app/scss/*.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sass({ style: 'expanded' }))
.pipe(gulp.dest('./app/css'))
.pipe(gulp.dest('./app/css'))
.pipe(notify({
title: 'Gulp',
subtitle: 'success',
message: 'Sass task success'
}));
});
// Clean Build Directory
gulp.task('cleanBuild',function(){
return gulp.src('dist/**/*', {read: false})
.pipe(clean());
});
// Deploy to Build Directory
gulp.task('deploy', gulp.series(['cleanBuild']), function(){
// optimasi css
var cssOptimize = gulp.src('app/css/*.css')
.pipe(cssnano())
.pipe(gulp.dest('dist/css/'));
// menggabung semua file js dan optimasi
var jsOptimize = gulp.src('app/js/*.js')
.pipe(concat('all.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
// optimasi image
var imgOptimize = gulp.src('app/images/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/images'))
// optimasi html
var htmlOptimize = gulp.src('app/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
// fonts folder
var fonts= gulp.src('app/fonts/**')
.pipe(gulp.dest('dist/fonts'));
return merge(cssOptimize,jsOptimize,imgOptimize,htmlOptimize,fonts);
});
// Deploy to Zip file
gulp.task('deployZip', gulp.series(['deploy']),function(){
var zipNow = gulp.src('dist/**')
.pipe(zip('deploy.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task('cfonts',function(){
gulp.src('app/fonts/**')
.pipe(gulp.dest('dist/fonts'));
});
// Default Task. Local webserver dan sinkronisasi dengan browser.
gulp.task('default', function(){
browserSync.init({
server: {
baseDir: "./app"
}
});
gulp.watch('./app/**/*').on('change', reload);
gulp.watch('./app/scss/*.scss', gulp.series(['sass']));
});