-
Notifications
You must be signed in to change notification settings - Fork 64
/
gulpfile.js
120 lines (93 loc) · 3.3 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
var fs = require('fs');
var del = require('del');
var browserSync = require('browser-sync');
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence'); // Temporary solution until Gulp 4
// https://github.com/gulpjs/gulp/issues/355
var reload = browserSync.reload;
// ---------------------------------------------------------------------
// | Helper tasks |
// ---------------------------------------------------------------------
gulp.task('clean', function () {
return del(['build']);
});
gulp.task('copy', [
'copy:css',
'copy:html',
'copy:misc'
]);
gulp.task('copy:css', function () {
return gulp.src('src/css/all.scss')
.pipe(plugins.sass({ style: 'compressed' }))
.pipe(gulp.dest('build/css'))
.pipe(plugins.filter('**/*.css'))
.pipe(reload({stream: true}));
});
gulp.task('copy:html', function () {
return gulp.src([
// Copy all `.html` files
'src/*.html',
// Exclude the following files since they
// are only used to build the other files
'!src/masthead.html',
'!src/base.html'
]).pipe(plugins.swig({
defaults: { cache: false },
data: JSON.parse(fs.readFileSync("./src/data.json"))
})).pipe(plugins.htmlmin({
// In-depth information about the options:
// https://github.com/kangax/html-minifier#options-quick-reference
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
// Prevent html-minifier from breaking the SVGs
// https://github.com/kangax/html-minifier/issues/285
keepClosingSlash: true,
caseSensitive: true
})).pipe(gulp.dest('build')).pipe(reload({stream: true}));
});
gulp.task('copy:misc', function () {
return gulp.src([
// Copy all files
'src/**',
// Exclude the following files
// (other tasks will handle the copying of these files)
'!src/*.html',
'!src/{css,css/**}',
'!src/data.json'
], {
// Include hidden files by default
dot: true
}).pipe(gulp.dest('build'));
});
gulp.task('browser-sync', function() {
browserSync({
// In-depth information about the options:
// http://www.browsersync.io/docs/options/
notify: false,
port: 8000,
server: "build",
open: false
});
});
gulp.task('watch', function () {
gulp.watch(['src/**/*.scss'], ['copy:css']);
gulp.watch(['src/*.html', 'src/data.json'], ['copy:html', reload]);
gulp.watch(['src/img/**', 'src/demos/**'], ['copy:misc']);
});
// ---------------------------------------------------------------------
// | Main tasks |
// ---------------------------------------------------------------------
gulp.task('build', function (done) {
runSequence('clean', 'copy', done);
});
gulp.task('default', ['build']);
gulp.task('serve', function (done) {
runSequence('build', ['browser-sync', 'watch'], done);
});