-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (106 loc) · 3.44 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
const config = require("./flightdeck.manifest")
// Load plugins
const { dest, src, watch, series, parallel } = require("gulp")
const argv = require("yargs").argv
const autoprefixer = require("autoprefixer")
const browsersync = require("browser-sync").create()
const cp = require("child_process")
const cssnano = require("cssnano")
const del = require("gulp-clean")
const newer = require("gulp-newer")
const plumber = require("gulp-plumber")
const postcss = require("gulp-postcss")
const sass = require("gulp-dart-sass")
const terser = require("gulp-terser")
const buildDest = `${config.jekyll.dest}/assets/`
// BrowserSync
function browserSync(done) {
browsersync.init({
server: {
baseDir: config.jekyll.dest,
},
port: config.port,
notify: config.bs.notify,
})
done()
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.notify("🛠 Site Rebuilt", 1000)
browsersync.reload()
done()
}
// Clean assets
function cleanAssets() {
return src(buildDest, { read: false, allowEmpty: true }).pipe(del())
}
// Optimize Images
async function images() {
const imagemin = await import("gulp-imagemin")
return src(config.assets + config.imagemin.src)
.pipe(newer(buildDest + config.imagemin.dest))
.pipe(
imagemin.default(
[
imagemin.gifsicle({ interlaced: config.imagemin.interlaced }),
imagemin.mozjpeg(config.imagemin.mozjpeg),
imagemin.optipng({
optimizationLevel: config.imagemin.optimizationLevel,
}),
],
{ verbose: config.imagemin.verbose },
),
)
.pipe(dest(buildDest + config.imagemin.dest))
}
// CSS task
function css() {
return src(config.assets + config.sass.src, { sourcemaps: true })
.pipe(plumber())
.pipe(sass({ outputStyle: config.sass.outputStyle }).on("error", sass.logError))
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(dest(buildDest + config.sass.dest, { sourcemaps: "." }))
.pipe(dest("assets/css"))
.pipe(browsersync.stream())
}
// Transpile, concatenate and minify scripts
function scripts() {
return src(config.assets + config.js.src, { sourcemaps: true })
.pipe(plumber())
.pipe(terser())
.pipe(dest(buildDest + config.js.dest, { sourcemaps: "." }))
.pipe(browsersync.stream())
}
// Jekyll
function jekyll(done) {
let jekyllConfig = config.jekyll.config.default
if (argv.jekyllEnv === "production") {
process.env.JEKYLL_ENV = "production"
jekyllConfig += `${config.jekyll.config.production ? `,${config.jekyll.config.production}` : ""}`
} else {
jekyllConfig += `${config.jekyll.config.development ? `,${config.jekyll.config.development}` : ""}`
}
return cp
.spawn("bundle", ["exec", "jekyll", "build", "--config", jekyllConfig], { stdio: "inherit" })
.on("close", done)
}
// Watch files
function watchFiles() {
watch(config.assets + config.sass.src, css)
watch(config.assets + config.js.src, series(scripts))
watch(config.jekyll.watch, series(jekyll, browserSyncReload))
watch(config.assets + config.imagemin.src, series(images, jekyll, browserSyncReload))
}
// define complex tasks
const js = series(scripts)
const build = series(cleanAssets, parallel(jekyll, css, js, images))
const monitor = parallel(watchFiles, browserSync)
// export tasks
exports.images = images
exports.css = css
exports.js = js
exports.jekyll = jekyll
exports.cleanAssets = cleanAssets
exports.build = build
exports.monitor = monitor
exports.default = series(build, monitor)