-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
78 lines (67 loc) · 2.07 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
const { src, dest, series } = require('gulp');
const luxon = require('luxon');
const replace = require('gulp-replace');
const purgecss = require('gulp-purgecss')
const htmlmin = require('gulp-htmlmin');
const cleanCSS = require('gulp-clean-css');
const concat = require('gulp-concat');
const del = require('del');
const cp = require("child_process");
const revAll = require("gulp-rev-all");
const clean = () => {
return del(['dist']);
}
const copyAssets = () => {
return src('src/assets/{images,js,fonts}/**')
.pipe(dest('dist/assets'));
}
// Base files (robots.txt, htaccess, etc...)
const copyBaseFiles = () => {
return src('src/base/**/*', { dot: true } )
.pipe(dest('dist'));
}
const build = () => {
return cp.spawn("npx", ["@11ty/eleventy"], { stdio: "inherit" });
}
const minifyHTML = () => {
const options = {
removeAttributeQuotes: true,
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
useShortDoctype: true
}
return src('dist/**/*.html')
.pipe(htmlmin(options))
.pipe(dest('dist'));
}
const purgeCSS = () => {
return src('src/assets/css/*.css')
.pipe(purgecss({
content: ['dist/**/*.html']
}))
.pipe(concat('all.min.css'))
.pipe(dest('dist/assets/css'));
}
const minifyCSS = () => {
return src('dist/assets/css/all.min.css')
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(dest('dist/assets/css'));
}
const securityTxt = () => {
return src('dist/.well-known/security.txt')
.pipe(replace("@date", luxon.DateTime.now().plus({ years: 2 }).startOf("day").toISO()))
.pipe(dest('dist/.well-known/'));
}
const revision = () => {
return src('dist/**')
.pipe(revAll.revision({ dontRenameFile: [/^\/logo-32x32.png$/g, ".html", ".json", ".txt"] }))
.pipe(dest("dist"))
.pipe(revAll.manifestFile())
.pipe(dest("dist"))
.pipe(revAll.versionFile())
.pipe(dest("dist"));
}
exports.build = build;
exports.default = series(clean, copyAssets, copyBaseFiles, build, minifyHTML, purgeCSS, minifyCSS, securityTxt, revision);