-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
66 lines (59 loc) · 1.37 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
const gulp = require('gulp');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const browsersync = require('browser-sync').create();
const panini = require('panini');
gulp.task('html', function() {
return gulp
.src('src/html/pages/**/*.html')
.pipe(
panini({
root: 'src/html/pages/',
layouts: 'src/html/layouts/',
partials: 'src/html/partials/',
helpers: 'src/html/helpers/',
data: 'src/html/data/'
})
)
.pipe(gulp.dest('public'));
});
gulp.task('resetPages', done => {
panini.refresh();
done();
});
function assets(callback) {
return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
if (err) {
return reject(err);
}
if (stats.hasErrors()) {
return reject(new Error(stats.compilation.errors.join('\n')));
}
resolve();
});
});
}
function serve(callback) {
browsersync.init(
{
server: './public',
port: 8080,
host: '0.0.0.0'
},
callback
);
}
function reload(cb) {
browsersync.reload();
cb();
}
function watch(cb) {
return gulp.watch(
'src/**/*',
// when something changes, rebuild + reload
gulp.series(assets, 'resetPages', 'html', reload)
);
}
exports.build = gulp.series(assets);
exports.dev = gulp.series('html', assets, serve, watch);