-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
127 lines (114 loc) · 3.25 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshintStylish = require('jshint-stylish');
var psi = require('psi');
var $ = require('gulp-load-plugins')();
var url = 'http://andrzejklapec.pl'; // INSERT YOUR SITE'S URL HERE
var basePath = {
src : 'assets/src/',
dest : 'assets/public/'
};
var srcAssets = {
styles : basePath.src + 'stylesheets/**/*',
scripts : basePath.src + 'scripts/*.js',
vendorScripts : basePath.src + 'scripts/vendor/**/*.js',
images : basePath.src + 'images/**/*'
};
var destAssets = {
styles : basePath.dest + 'stylesheets/',
scripts : basePath.dest + 'scripts/',
vendorScripts : basePath.dest + 'scripts/',
images : basePath.dest + 'images/'
};
function errorAlert(err) {
$.notify.onError({
title: "Gulp Error",
message: "Check your terminal",
sound: "Basso"
})(err);
gutil.log(gutil.colors.red(err.toString()));
this.emit("end");
}
gulp.task('default', ['styles', 'scripts', 'vendorScripts', 'images'], function() {
gulp.watch(srcAssets.styles, ['styles']);
gulp.watch(srcAssets.scripts, ['scripts']);
gulp.watch(srcAssets.vendorScripts, ['vendorScripts']);
gulp.watch(srcAssets.images, ['images']);
});
gulp.task('styles', function() {
return gulp.src(srcAssets.styles + 'main.scss')
.pipe($.plumber({errorHandler: errorAlert}))
.pipe($.sass({
precision: 6
}))
.pipe($.autoprefixer({
browsers: ['last 2 versions']
}))
.pipe($.minifyCss())
.pipe($.rename({
suffix: ".min"
}))
.pipe(gulp.dest(destAssets.styles))
.pipe($.notify({
title: "Stylesheets recompiled",
message: "<%= file.relative %>",
sound: "Glass"
}));
});
gulp.task('scripts', function() {
return gulp.src(srcAssets.scripts)
.pipe($.plumber({errorHandler: errorAlert}))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.concat('main.min.js'))
.pipe($.uglify())
.pipe(gulp.dest(destAssets.scripts))
.pipe($.notify({
title: "Scripts recompiled",
message: "<%= file.relative %>",
sound: "Glass"
}));
});
gulp.task('vendorScripts', function() {
return gulp.src(srcAssets.vendorScripts)
.pipe($.plumber({errorHandler: errorAlert}))
.pipe($.concat('vendor.min.js'))
.pipe($.uglify())
.pipe(gulp.dest(destAssets.vendorScripts))
.pipe($.notify({
title: "Vendor scripts recompiled",
message: "<%= file.relative %>",
sound: "Glass"
}));
});
gulp.task('images', function() {
return gulp.src(srcAssets.images)
.pipe($.plumber({errorHandler: errorAlert}))
.pipe($.changed(destAssets.images))
.pipe($.imagemin({
optimizationLevel: 1,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(destAssets.images))
.pipe($.notify({
title: "Images optimized",
message: "<%= file.relative %>",
sound: "Glass"
}));
});
gulp.task('perf', ['perfMobile', 'perfDesktop']);
gulp.task('perfMobile', function(cb) {
psi({
nokey: 'true',
url: url,
strategy: 'mobile',
}, cb);
});
gulp.task('perfDesktop', function(cb) {
psi({
nokey: 'true',
url: url,
strategy: 'desktop',
}, cb);
});