-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (95 loc) · 2.71 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
'use strict';
// DEPENDENCIES =======================================================
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var pagespeed = require('psi');
var reload = browserSync.reload;
// FILE PATHS =========================================================
var source = {
styles : 'source/styles/**/*.scss',
scripts : 'source/scripts/*.js',
images : 'source/images/*.{png,jpg,gif}',
svgs : 'source/images/*.svg'
};
var assets = {
styles : 'assets/styles',
scripts : 'assets/scripts',
images : 'assets/images'
};
// AUTOPREFIXER CONFIG ================================================
var AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
// COMPILE STYLESHEETS ================================================
gulp.task('styles', function () {
return gulp.src('source/styles/*.scss')
.pipe($.changed('styles', {
extension: '.scss'
}))
.pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'SASS error:')
}))
.pipe($.autoprefixer({
browsers: AUTOPREFIXER_BROWSERS
}))
.pipe($.csso())
.pipe(gulp.dest(assets.styles))
.pipe($.size({title: 'styles'}));
});
// LINT & CONCATENATE JS ==============================================
gulp.task('scripts', function () {
return gulp.src(source.scripts)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.uglify())
.pipe(gulp.dest(assets.scripts));
});
// OPTIMISE IMAGES ====================================================
gulp.task('images', function () {
return gulp.src(source.images)
.pipe($.changed(assets.images))
.pipe($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(assets.images));
});
// CREATE SVG SPRITE ==================================================
gulp.task('sprite', function () {
return gulp.src(source.svgs)
.pipe($.svgSprite({
mode: {
symbol: {
dest: './',
sprite: 'sprite.symbol.svg'
}
}
}))
.pipe(gulp.dest(assets.images));
});
// WATCH FOR CHANGES AND RELOAD =======================================
gulp.task('serve', ['styles'], function () {
browserSync({
notify: false,
// Customize the BrowserSync console logging prefix
logPrefix: '⎋',
server: './'
});
gulp.watch(['**/*.html'], reload);
gulp.watch([source.styles], ['styles', reload]);
gulp.watch([source.scripts], ['scripts']);
gulp.watch([source.images], ['images', reload]);
});