-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (106 loc) · 2.52 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
var gulp = require('gulp')
, critical = require('critical')
, del = require('del')
, browserSync = require('browser-sync').create()
, reload = browserSync.reload
, $ = require('gulp-load-plugins')();
var paths = {
jadeSrc: './src/**/*.jade',
stylusSrc: './src/**/*.styl',
imageSrc: [
'./src/**/*.jpeg',
'./src/**/*.jpg',
'./src/**/*.svg',
'./src/**/*.png',
'./src/**/*.gif'
],
destination: './build',
cssSrc: './build/css/main.css'
};
gulp.task('html', function() {
gulp.src(paths.jadeSrc)
.pipe($.jade({ doctype: 'html' }))
.pipe($.minifyInline())
.on('error', $.util.log)
.pipe(gulp.dest(paths.destination))
.pipe(browserSync.stream({once: true}));
});
gulp.task('css', function() {
gulp.src(paths.stylusSrc)
.pipe($.stylus({
'include css': true,
compress: true
}))
.pipe($.concat(paths.cssSrc))
.pipe($.combineMq({ beatify: false }))
.pipe($.uncss({
html: ['./build/**/*.html'],
ignore: [
'a:link',
'a:hover',
'a:focus',
'a:active',
'a:visited',
'.fade',
'.fade.in',
'.collapse',
'.collapse.in',
'.collapsing',
/\.open/
]
}))
.pipe($.autoprefixer())
.pipe($.minifyCss({ keepSpecialComments: false }))
.pipe(gulp.dest('./'))
.pipe(browserSync.stream({once: true}));
});
gulp.task('image', function() {
gulp.src(paths.imageSrc)
.pipe($.imagemin({
optimizationLevel: 7,
progressive: true,
iterlaced: true
}))
.pipe(gulp.dest(paths.destination));
});
gulp.task('critical', ['build'], function() {
critical.generate({
base: './build/',
src: 'index.html',
dest: 'tmp/main.css',
minify: true,
dimensions: [{
width: 350,
height: 575
}, {
width: 500,
height: 575
}, {
width: 1300,
height: 900
}]
}, function(err, output) {
critical.inline({
base: './build',
src: 'index.html',
dest: './build/index.html',
minify: true
})
})
});
gulp.task('clean:tmp', function() {
del('tmp');
});
gulp.task('dev-server', ['default', 'critical'], function() {
browserSync.init({
server: paths.destination
});
gulp.watch(paths.jadeSrc, ['default']);
gulp.watch(paths.stylusSrc, ['default']);
});
gulp.task('build', ['html', 'css', 'image'], function() {
});
gulp.task('dev', ['build', 'critical', 'dev-server'], function() {
});
gulp.task('default', ['build', 'critical', 'clean:tmp'], function() {
});