-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
130 lines (98 loc) · 3.01 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
var gulp = require('gulp'),
del = require('del'),
browserSync = require('browser-sync').create(),
inlineCss = require('gulp-inline-css'),
sass = require('gulp-sass'),
smoosher = require('gulp-smoosher'),
plumber = require('gulp-plumber'),
gutil = require('gulp-util'),
runSequence = require('run-sequence');
// lets gulp throw errors during watch without stopping
var onError = function (err) {
gutil.beep();
console.log(err);
};
//------------------------
// Sass Gulp Task
//------------------------
gulp.task('sass', function () {
gulp.src('_input/sass/*.scss')
.pipe(plumber({
errorHandler: onError
}))
.pipe(sass())
.pipe(browserSync.reload({
stream: true
}))
.pipe(gulp.dest('css'));
});
//------------------------
// Watch Gulp Task
//------------------------
gulp.task('watch', function(){
gulp.watch('_input/sass/**/*.*', ['sass'])
});
//------------------------
// Smoosher Gulp Task
//------------------------
gulp.task('smoosher', function () {
return gulp.src('_input/*.html')
.pipe(smoosher())
.pipe(gulp.dest('tmp'));
});
//------------------------
// InlineCss Gulp Task
//------------------------
gulp.task('inlineCss', function() {
return gulp.src('tmp/*.html')
.pipe(inlineCss({
// Whether to inline styles in <style></style>
applyStyleTags: false,
// Whether to resolve <link rel="stylesheet"> tags and inline the resulting styles
applyLinkTags: true,
// Whether to remove the original <style></style> tags
removeStyleTags: false,
// Whether to remove the original <link rel="stylesheet">
removeLinkTags: true,
// Preserves all media queries (and contained styles) within <style></style> tags
preserveMediaQueries: true,
}))
.pipe(gulp.dest('_output/'));
});
//------------------------
// Clean Gulp Task
//------------------------
// deletes existing folders in output which will be replaced by inlined versions of _input files
gulp.task('clean:output', function() {
return del([
'_output/**/*'
]);
});
// delets tmp folder that is created to add media queries
gulp.task('clean:tmp', function() {
return del([
'tmp'
]);
});
//------------------------
// Browsersync Gulp Task
//------------------------
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: "./"
}
});
// gulp.watch("_input/sass/.scss", ['sass']);
gulp.watch("_input/*.html").on('change', browserSync.reload);
});
//------------------------
// Task Config
//------------------------
//default gulp task.
gulp.task('default', ['sass', 'watch', 'browser-sync']);
// Pulls in media queries, css, then deletes tmp folder
gulp.task('build', function(callback) {
runSequence('clean:output', 'sass','smoosher','inlineCss', 'clean:tmp',
callback);
});