-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
153 lines (119 loc) · 4.08 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// REQUIRES & CONFIG
const gulp = require('gulp')
const util = require('gulp-util')
// General utilities
const del = require('del')
const sourcemaps = require('gulp-sourcemaps')
const concat = require('gulp-concat')
const gulpfilter = require('gulp-filter')
// HTML and Journal
const pug = require('gulp-pug')
const htmlmin = require('gulp-htmlmin')
// CSS
const sass = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer')
const csso = require('gulp-csso')
// JavaScript
const browserify = require('gulp-browserify')
const uglify = require('gulp-uglify')
// Development
const watch = require('gulp-watch')
const connect = require('gulp-connect')
const paths = {
pages: 'source/content/**/*.pug',
templates: 'source/assets/templates/**/*.pug',
stylesheets: 'source/assets/stylesheets/site.scss',
watchStylesheets: 'source/assets/stylesheets/**/*.scss',
scripts: 'source/assets/scripts/site.js',
watchScripts: 'source/assets/scripts/**/*.+(js|coffee)',
images: 'source/assets/images/**/*.+(png|jpg|gif|svg)',
fonts: 'source/assets/fonts/**/*',
icons: 'source/assets/icons/**/*',
other: [ 'source/assets/**/*.*',
"!source/assets/+(templates|stylesheets|scripts|images|icons)/**/*.*" ]
}
const config = require('./config.json')
config.production = !!util.env.production
// TASKS
gulp.task('clean', cb => del(['public'], cb))
const taskStylesheets = () => {
gulp.src(paths.stylesheets)
.pipe(gulpfilter([ '**', '!**/_*' ]))
.pipe(config.production ? util.noop() : sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(concat('site.css'))
.pipe(config.production ? csso() : util.noop())
.pipe(config.production ? util.noop() : sourcemaps.write())
.pipe(gulp.dest('public/css'))
.pipe(config.production ? util.noop() : connect.reload())
}
gulp.task('stylesheets', ['clean'], taskStylesheets)
gulp.task('stylesheets-watch', taskStylesheets)
const taskScripts = () => {
gulp.src(paths.scripts)
.pipe(gulpfilter([ '**', '!**/_*' ]))
.pipe(browserify({
debug : !config.production
}))
.pipe(config.production ? uglify() : util.noop())
.pipe(concat('site.js'))
.pipe(gulp.dest('public/js'))
.pipe(config.production ? util.noop() : connect.reload())
}
gulp.task('scripts', ['clean'], taskScripts)
gulp.task('scripts-watch', taskScripts)
const taskMedia = () => {
// Images
gulp.src(paths.images, { base: 'source/assets/images' })
.pipe(gulpfilter([ '**', '!**/_*' ]))
.pipe(gulp.dest('public/img'))
.pipe(config.production ? util.noop() : connect.reload())
// Fonts
gulp.src(paths.fonts)
.pipe(gulp.dest('public/fonts'))
.pipe(config.production ? util.noop() : connect.reload())
// Icons
gulp.src(paths.icons)
.pipe(gulp.dest('public'))
.pipe(config.production ? util.noop() : connect.reload())
// Misc
gulp.src(paths.other)
.pipe(gulp.dest('public'))
.pipe(config.production ? util.noop() : connect.reload())
}
gulp.task('media', ['clean'], taskMedia)
gulp.task('media-watch', taskMedia)
const taskPages = () => {
gulp.src(paths.pages)
.pipe(gulpfilter([ '**', '!**/_*' ]))
.pipe(pug({ locals: { config: config }}))
.pipe(config.production ? htmlmin({ comments: true,
conditionals: true,
cdata: true,
quotes: true,
collapseWhitespace: true,
minifyCSS: true
}): util.noop())
.pipe(gulp.dest('public'))
.pipe(config.production ? util.noop() : connect.reload())
}
gulp.task('pages', ['clean'], taskPages)
gulp.task('pages-watch', taskPages)
// DEVELOPMENT TASKS
gulp.task('watch', ['default'], () => {
gulp.watch([ paths.watchStylesheets ], [ 'stylesheets-watch' ])
gulp.watch([ paths.watchScripts ], ['scripts-watch'])
gulp.watch([ paths.images, paths.fonts, paths.icons, paths.other ], ['media-watch'])
gulp.watch([ paths.pages, paths.templates ], ['pages-watch' ])
})
gulp.task('server', ['default'], () => {
connect.server({
root: 'public',
livereload: true
})
})
// TASK GROUPS
gulp.task('assets', [ 'stylesheets', 'scripts', 'media' ])
gulp.task('default', [ 'clean', 'assets', 'pages' ])
gulp.task('dev', [ 'default', 'watch', 'server' ])