-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
118 lines (105 loc) · 3.13 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
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass')(require('sass'));
const htmlmin = require('gulp-htmlmin');
const purgecss = require('gulp-purgecss')
const cssmin = require('gulp-cssmin');
const imagemin = require('gulp-imagemin');
const concat = require('gulp-concat');
const jsImport = require('gulp-js-import');
const terser = require('gulp-terser');
const sourcemaps = require('gulp-sourcemaps');
const htmlPartial = require('gulp-html-partial');
const clean = require('gulp-clean');
const isProd = process.env.NODE_ENV === 'prod';
const htmlFile = [
'src/*.html'
]
const njk = require('gulp-nunjucks-render')
const beautify = require('gulp-beautify')
const sitemap = require('gulp-sitemap');
function html() {
return gulp.src('src/html/pages/**/*.+(html|njk)')
.pipe(
njk({
path: ['src/html'],
})
)
.pipe(beautify.html({ indent_size: 4, preserve_newlines: false }))
.pipe(gulp.dest('docs'))
}
function css() {
return gulp.src('src/sass/style.scss')
.pipe(gulpIf(!isProd, sourcemaps.init()))
.pipe(sass({
includePaths: ['node_modules']
}).on('error', sass.logError))
.pipe(gulpIf(!isProd, sourcemaps.write()))
.pipe(gulpIf(isProd, purgecss({
content: ['src/**/*.html', 'src/**/*.js']
})))
.pipe(gulpIf(isProd, cssmin()))
.pipe(gulp.dest('docs/css/'));
}
function js() {
return gulp.src('src/js/*.js')
.pipe(jsImport({
hideConsole: true
}))
.pipe(concat('all.js'))
.pipe(gulpIf(isProd, terser()))
.pipe(gulp.dest('docs/js'));
}
function img() {
return gulp.src('src/img/*')
.pipe(gulpIf(isProd, imagemin()))
.pipe(gulp.dest('docs/img/'));
}
function serve() {
browserSync.init({
open: true,
server: {
baseDir: "docs",
serveStaticOptions: {
extensions: ['html']
}
}
});
}
function browserSyncReload(done) {
browserSync.reload();
done();
}
function watchFiles() {
gulp.watch('src/**/*.html', gulp.series(html, browserSyncReload));
gulp.watch('src/**/*.njk', gulp.series(html, browserSyncReload));
gulp.watch('src/**/*.scss', gulp.series(css, browserSyncReload));
gulp.watch('src/**/*.js', gulp.series(js, browserSyncReload));
gulp.watch('src/img/**/*.*', gulp.series(img));
return;
}
function del() {
return gulp.src('docs/*', {read: false})
.pipe(clean());
}
function copy() {
return gulp.src('./CNAME')
.pipe(gulp.dest('./docs/'));
}
async function createSitemap() {
gulp.src('docs/**/*.html', {
read: false
})
.pipe(sitemap({
siteUrl: 'https://bootiful.org'
}))
.pipe(gulp.dest('./docs'));
}
exports.css = css;
exports.copy = copy;
exports.html = html;
exports.js = js;
exports.del = del;
exports.serve = gulp.parallel(html, css, js, img, watchFiles, serve);
exports.default = gulp.series(del, copy, html, css, js, img, createSitemap);