-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
91 lines (83 loc) · 2.14 KB
/
gulpfile.js
File metadata and controls
91 lines (83 loc) · 2.14 KB
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
/*
Install these with 'npm i -D <name>' to save dev dependencies in package.json.
*/
var browserSync = require('browser-sync');
var del = require('del');
var filter = require('gulp-filter');
var gulp = require('gulp');
var pug = require('gulp-pug');
var runSequence = require('run-sequence');
var dir = {
root: './',
dist: './dist/',
pages: './pages/',
pages_all: './pages/**/*.{pug,md}',
pages_pug: './pages/**/*.pug',
// styles: './styles/**/*.css',
styles: './styles/**/*',
scripts: './scripts/**/*',
};
gulp.task('build_clean', function() {
return del([
dir.dist + '**/*',
'!' + dir.dist + 'fonts/**',
'!' + dir.dist + 'images/**',
]);
});
gulp.task('build_styles', function() {
return gulp
.src(dir.styles)
.pipe(browserSync.reload({ stream: true }))
.pipe(gulp.dest(dir.dist + 'styles/'));
});
gulp.task('build_scripts', function() {
return gulp.src(dir.scripts).pipe(gulp.dest(dir.dist + 'scripts/'));
});
gulp.task('build_pages', function() {
return (
gulp
.src(dir.pages_pug)
.pipe(pug({ basedir: dir.pages }))
// .pipe(pug({ basedir: dir.pages, pretty: true }))
.pipe(
filter(function(file) {
return !/\/_/.test(file.path) && !/^_/.test(file.relative);
}),
)
.pipe(gulp.dest(dir.dist))
);
});
gulp.task('build_headers', function() {
return gulp.src('_headers').pipe(gulp.dest(dir.dist));
});
gulp.task('build', function(done) {
runSequence(
'build_clean',
['build_styles', 'build_scripts', 'build_headers'],
'build_pages',
done,
);
});
gulp.task('watch', ['build'], function() {
browserSync({
server: dir.dist,
ghostMode: {
scroll: true,
},
snippetOptions: {
ignorePaths: '',
},
rewriteRules: [
{
match: "script-src 'self';",
replace:
"script-src 'self' '" +
'sha256-7+J4BBpfP6BrGwq4jUTZH0MyBpT74yWhCBZ2TproeZY=' +
"'; connect-src ws: 'self';",
},
],
});
gulp.watch(dir.styles, ['build_styles']);
gulp.watch(dir.scripts, ['build_scripts', browserSync.reload]);
gulp.watch(dir.pages_all, ['build_pages', browserSync.reload]);
});