-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
230 lines (201 loc) · 6.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*!
* gulp
* $ npm install gulp-ruby-sass gulp-image-resize gulp-autoprefixer gulp-minify-css gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
*/
// Load plugins
var gulp = require('gulp'), //importing gulp library and storing in variable "gulp"
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
del = require('del');
imageResize = require('gulp-image-resize')
// Styles dont want to use sass one
// gulp.task('styles', function() {
// return sass('src/styles/main.scss', { style: 'expanded' })
// .pipe(autoprefixer('last 2 version'))
// .pipe(gulp.dest('dist/styles'))
// .pipe(rename({ suffix: '.min' }))
// .pipe(minifycss())
// .pipe(gulp.dest('dist/styles'))
// .pipe(notify({ message: 'Styles task complete' }));
// });
gulp.task('styles', function(){
return gulp.src('css/*.css')
.pipe(autoprefixer({
browsers: ['last 2 versions'] //newly added and not tested
}))
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css'));
});
// Scripts
gulp.task('scripts', function() {
return gulp.src('js/*.js')
//.pipe(jshint('.jshintrc'))
//.pipe(jshint.reporter('default'))
//.pipe(concat('combined.js'))
//.pipe(gulp.dest('dist/js'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
.pipe(notify({ message: 'Scripts task complete' }));
});
// Images
gulp.task('images', function() {
return gulp.src('images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true })))
.pipe(gulp.dest('images/compressed'))
.pipe(notify({ message: 'Images task complete' }));
});
// Images Resize
gulp.task('resize1', function () { //540 resize
return gulp.src('images/compressed/*.{jpg,png,jpeg}')
.pipe(imageResize({
width : 540,
crop : false,
imageMagick : true,
upscale : false
}))
.pipe(rename({ suffix: '-540' }))
.pipe(gulp.dest('dist/img'));
});
gulp.task('resize2', function () { //780 resize
return gulp.src('images/compressed/*.{jpg,png,jpeg}')
.pipe(imageResize({
width : 780,
crop : false,
imageMagick : true,
upscale : false
}))
.pipe(rename({ suffix: '-780' }))
.pipe(gulp.dest('dist/img'));
});
gulp.task('resize3', function () { //1920 resize
return gulp.src('images/compressed/*.{jpg,png,jpeg}')
.pipe(imageResize({
width : 1920,
crop : false,
imageMagick : true,
upscale : false
}))
.pipe(rename({ suffix: '-1920' }))
.pipe(gulp.dest('dist/img'));
});
gulp.task('resize4', function () { //resizing my landscape hero image for vertical small devices
return gulp.src('images/compressed/*.{jpg,png,jpeg}')
.pipe(imageResize({
height : 640,
width : 400,
crop : true,
imageMagick : true,
upscale : true
}))
.pipe(rename({ suffix: '-640h' }))
.pipe(gulp.dest('dist/img'));
});
gulp.task('resize5', function () { //resizing my landscape hero image for vertical mid devices
return gulp.src('images/compressed/*.{jpg,png,jpeg}')
.pipe(imageResize({
height : 900,
crop : true,
imageMagick : true,
upscale : true
}))
.pipe(rename({ suffix: '-900h' }))
.pipe(gulp.dest('dist/img'));
});
gulp.task('resize6', function () { //540 resize
return gulp.src('images/compressed/bendriver.jpg')
.pipe(imageResize({
width : 300,
crop : false,
imageMagick : true,
upscale : false
}))
.pipe(rename({ suffix: '-300' }))
.pipe(gulp.dest('dist/img'));
});
// Clean
gulp.task('clean', function(cb) {
del(['dist/css', 'dist/js', 'dist/img'], cb)
});
//tasks for web optimization and clean
gulp.task('weboptclean', function(cb) {
del(['web-optimize/dist/css', 'web-optimize/dist/js', 'web-optimize/dist/images', 'web-optimize/views/dist/images'], cb)
});
// Scripts for web opt
gulp.task('weboptscripts', function() {
return gulp.src('web-optimize/js/**/*.js')
//.pipe(jshint('.jshintrc'))
//.pipe(jshint.reporter('default'))
.pipe(concat('perfmatters.js'))
.pipe(gulp.dest('web-optimize/dist/js'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('web-optimize/dist/js'))
.pipe(notify({ message: 'Scripts task complete' }));
});
// Images
gulp.task('weboptimages', function() {
return gulp.src('web-optimize/img/**/*')
.pipe(cache(imagemin({ optimizationLevel: 6, progressive: true, interlaced: true })))
.pipe(gulp.dest('web-optimize/dist/images'))
.pipe(notify({ message: 'Images task complete' }));
});
// pizza Images
gulp.task('pizzaimages', function() {
return gulp.src('web-optimize/views/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('web-optimize/views/dist/images'))
.pipe(notify({ message: 'Images task complete' }));
});
//pizzaresize
gulp.task('pizzaresize', function () { //540 resize
return gulp.src('web-optimize/views/images/pizzeria-780.jpg')
.pipe(imageResize({
width : 300,
crop : false,
imageMagick : true,
upscale : false
}))
.pipe(rename({ suffix: '-300' }))
.pipe(gulp.dest('web-optimize/views/images'));
});
gulp.task('weboptstyles', function(cb) {
return gulp.src('web-optimize/css/*.css')
.pipe(autoprefixer({
browsers: ['last 2 versions'] //newly added and not tested
}))
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('web-optimize/dist/css'));
});
// web op Default task
gulp.task('weboptdefault', function() { //two parameters, takes name and function
gulp.start('weboptstyles', 'weboptimages', 'weboptscripts', 'pizzaimages');
});
// Default task
gulp.task('default', function() { //two parameters, takes name and function
gulp.start('styles', 'images');
});
// Watch
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('css/**/*.css', ['styles']);
// Watch .js files
gulp.watch('js/**/*.js', ['scripts']); //specify files you want to watch and what tasks you want to run when changes get detected in those files
// Watch image files
gulp.watch('images/**/*', ['images']);
// Create LiveReload server
livereload.listen();
// Watch any files in dist/, reload on change
gulp.watch(['dist/**']).on('change', livereload.changed);
});