-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (65 loc) · 1.75 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
const gulp = require('gulp');
const handlebars = require('gulp-compile-handlebars');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const gulpCopy = require('gulp-copy');
var browserSync = require('browser-sync').create();
sass.compile = require('node-sass');
// Compile Handlebars pages - need to restart watching if changes are made to partials.
gulp.task('html', () => {
return gulp.src('./src/pages/*.hbs', './src/partials/**/*.hbs')
.pipe(handlebars({}, {
ignorePartials: true,
batch: ['./src/partials']
}))
.pipe(rename({
extname: '.html'
}))
.pipe(gulp.dest('./dist'));
});
// Compile sass to css.
gulp.task('sass', () => {
return gulp.src('./src/sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/css'));
});
// Copy Images
gulp.task('copyImg', (cb) => {
return gulp.src('./src/img/**/*')
.pipe(gulpCopy('./dist/img', { prefix: 2 }));
cb();
});
// Copy JS
gulp.task('copyJs', (cb) => {
return gulp.src('./src/js/**/*')
.pipe(gulpCopy('./dist/js', { prefix: 2 }));
cb();
});
// Reload function for browserSync
function reload() {
browserSync.reload();
}
// Watch css and handlebars changes.
gulp.task('watch', () => {
browserSync.init({
server: {
baseDir: "./dist"
}
});
gulp.watch('./src/sass/**/*.scss', gulp.series('sass'));
gulp.watch(['./src/pages/*.hbs', './src/partials/**/*.hbs'], gulp.series('html'));
gulp.watch('./src/img/**/*', gulp.series('copyImg'));
gulp.watch('./src/js/**/*', gulp.series('copyJs'));
gulp.watch('./dist/**/*', reload);
});
// Build site initially
gulp.task('build', gulp.series(
'sass',
'html',
'copyImg',
'copyJs'
));
gulp.task('default', gulp.series(
'build',
'watch'
));