-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
68 lines (58 loc) · 1.88 KB
/
gulpfile.babel.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
'use strict';
import browser from 'browser-sync';
import gulp from 'gulp';
import panini from 'panini';
import plugins from 'gulp-load-plugins';
import rimraf from 'rimraf';
import yargs from 'yargs';
const $ = plugins();
const ARGS = yargs.argv;
const PRODUCTION = !!(ARGS.production);
const PATH_DIST = 'dist'
gulp.task('watch', gulp.series(clean, gulp.parallel(pages, sass), server, watch));
gulp.task('build', gulp.series(clean, gulp.parallel(pages, sass)));
gulp.task('default', gulp.series('watch'));
function clean(done) {
rimraf(PATH_DIST, done);
}
function pages() {
return gulp.src('src/pages/**/*.{html,hbs,handlebars}')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
// data: 'src/data/',
// helpers: 'src/helpers/'
}))
.pipe(gulp.dest(PATH_DIST));
}
function resetPages(done) {
panini.refresh();
done();
}
function sass() {
return gulp.src('src/scss/*.scss')
.pipe($.if(!PRODUCTION, $.sourcemaps.init()))
.pipe($.sass().on('error', $.sass.logError))
.pipe($.autoprefixer({ browsers: ['last 2 versions', 'ie >= 9', 'ios >= 7'] }))
.pipe($.if(PRODUCTION, $.cleanCss({ compatibility: 'ie9' })))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest(PATH_DIST + '/css'))
.pipe(browser.reload({ stream: true }))
}
function server(done) {
browser.init({
server: PATH_DIST,
port: 8000
});
done();
}
function reload(done) {
browser.reload();
done();
}
function watch() {
gulp.watch('src/pages/**/*.html').on('all', gulp.series(pages, browser.reload));
gulp.watch('src/{layouts,partials}/**/*.html').on('all', gulp.series(resetPages, pages, browser.reload));
gulp.watch('src/scss/**/*.scss').on('all', gulp.series(sass, browser.reload));
}