-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgulpfile.js
More file actions
154 lines (130 loc) · 3.79 KB
/
gulpfile.js
File metadata and controls
154 lines (130 loc) · 3.79 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// Gulpfile
//
var gulp = require('gulp'),
sass = require('gulp-sass'),
changed = require('gulp-changed'),
autoprefixer = require('gulp-autoprefixer'),
rename = require('gulp-rename'),
del = require('del'),
concat = require('gulp-concat'),
cssnano = require('gulp-cssnano'),
uglify = require('gulp-uglifyjs'),
cache = require('gulp-cache'),
imagemin = require('gulp-imagemin'),
imageminJpegRecompress = require('imagemin-jpeg-recompress'),
pngquant = require('imagemin-pngquant'),
browserSync = require('browser-sync').create();
//
// Gulp plumber error handler - displays if any error occurs during the process on your command
//
function errorLog(error) {
console.error.bind(error);
this.emit('end');
}
//
// SASS - Compile SASS files into CSS
//
gulp.task('sass', function () {
// Theme
gulp.src('./assets/include/scss/**/*.scss')
.pipe(changed('./assets/css/'))
.pipe(sass({ outputStyle: 'expanded' }))
.on('error', sass.logError)
.pipe(autoprefixer([
"last 1 major version",
">= 1%",
"Chrome >= 45",
"Firefox >= 38",
"Edge >= 12",
"Explorer >= 10",
"iOS >= 9",
"Safari >= 9",
"Android >= 4.4",
"Opera >= 30"], { cascade: true }))
.pipe(gulp.dest('./assets/css/'))
.pipe(browserSync.stream());
});
//
// BrowserSync (live reload) - keeps multiple browsers & devices in sync when building websites
//
//
gulp.task('serve', function() {
browserSync.init({
files: "./*.html",
startPath: "./index.html",
server: {
baseDir: "./",
routes: {},
middleware: function (req, res, next) {
if (/\.json|\.txt|\.html/.test(req.url) && req.method.toUpperCase() == 'POST') {
console.log('[POST => GET] : ' + req.url);
req.method = 'GET';
}
next();
}
}
})
});
//
// Gulp Watch and Tasks
//
//
gulp.task('watch', function() {
gulp.watch('./assets/include/scss/**/*.scss', ['sass']);
gulp.watch('./html/**/*.html').on('change', browserSync.reload);
gulp.watch('./starter/**/*.html').on('change', browserSync.reload);
gulp.watch('./documentation/**/*.html').on('change', browserSync.reload);
});
// Gulp Tasks
gulp.task('default', ['watch', 'sass', 'serve'])
//
// CSS minifier - merges and minifies the below given list of Front libraries into one theme.min.css
//
gulp.task('minCSS', function() {
return gulp.src([
'./assets/css/theme.css',
])
.pipe(cssnano())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./dist/assets/css/'));
});
//
// JavaSript minifier - merges and minifies the below given list of Front libraries into one theme.min.js
//
gulp.task('minJS', function() {
return gulp.src([
'./assets/js/main.js',
'./assets/js/autocomplete.js',
'./assets/js/custom-scrollbar.js',
'./assets/js/sticky-sidebar.js',
'./assets/js/header-fixing.js',
'./assets/js/theme-custom.js'
])
.pipe(concat('theme.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist/assets/js/'));
});
//
// Image minifier - compresses images automatically
//
gulp.task('minIMG', function() {
return gulp.src('./assets/img-temp/**/*')
.pipe(cache(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imageminJpegRecompress({
loops: 5,
min: 65,
max: 70,
quality:'medium'
}),
imagemin.svgo(),
imagemin.optipng({optimizationLevel: 3}),
pngquant({quality: '65-70', speed: 5})
],{
verbose: true
})))
.pipe(gulp.dest('./dist/assets/img-temp/'));
});
gulp.task('dist', ['minCSS', 'minJS', 'minIMG']);