-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
111 lines (96 loc) · 2.86 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
'use strict';
var gulp = require('gulp');
var path = require('path');
var $ = require('gulp-load-plugins')();
var paths = {
src: 'src',
tmp: '.tmp',
dist: 'build',
stylesheets: 'src/stylesheets/**/*.{sass,scss,css}',
pages: 'src/templates/pages/*.haml',
partials: 'src/templates/partials/**/*.haml',
layouts: 'src/templates/layouts/*.haml',
images: 'src/images/**/*',
fonts: 'src/fonts/**/*.{eot,svg,ttf,woff}',
};
gulp.task('sass', function() {
return gulp.src(paths.stylesheets)
.pipe($.plumber())
.pipe($.rubySass({
style: 'expanded',
lineNumbers: true,
sourcemap: true,
compass: true,
}))
.pipe($.autoprefixer('last 1 version'))
.pipe(gulp.dest(path.join(paths.tmp, 'stylesheets')))
.pipe($.connect.reload());
});
gulp.task('assemble:partials', function() {
return gulp.src(paths.partials)
.pipe($.plumber())
.pipe($.rubyHaml())
.pipe(gulp.dest(path.join(paths.tmp, 'partials')));
});
gulp.task('assemble:layouts', function() {
return gulp.src(paths.layouts)
.pipe($.plumber())
.pipe($.rubyHaml())
.pipe(gulp.dest(path.join(paths.tmp, 'layouts')));
});
gulp.task('assemble', ['assemble:partials', 'assemble:layouts'], function() {
return gulp.src(paths.pages)
.pipe($.plumber())
.pipe($.rubyHaml())
.pipe($.assemble({
partials: path.join(paths.tmp, 'partials', '**/*.html'),
layoutdir: path.join(paths.tmp, 'layouts'),
layout: 'default',
layoutext: '.html',
}))
.pipe(gulp.dest(paths.tmp))
.pipe($.connect.reload());
});
gulp.task('connect', function() {
$.connect.server({
root: [paths.tmp, paths.src],
livereload: true,
port: 9000,
});
});
gulp.task('watch', function() {
gulp.watch([paths.pages, paths.partials, paths.layouts], ['assemble']);
gulp.watch([paths.stylesheets], ['sass']);
});
gulp.task('html', ['assemble', 'sass'], function() {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src(path.join(paths.tmp, '*.html'))
.pipe($.plumber())
.pipe($.useref.assets({searchPath: [paths.tmp, paths.src]}))
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest(paths.dist));
});
gulp.task('images', function() {
return gulp.src(paths.images)
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true,
})))
.pipe(gulp.dest(path.join(paths.dist, 'images')));
});
gulp.task('fonts', function() {
return gulp.src(paths.fonts)
.pipe(gulp.dest(path.join(paths.dist, 'fonts')));
});
gulp.task('clean', require('del').bind(null, [paths.tmp, paths.dist]));
gulp.task('build', ['html', 'images', 'fonts']);
gulp.task('default', ['assemble', 'sass', 'connect', 'watch']);