forked from DMarby/picsum-photos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
49 lines (40 loc) · 1.04 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
const del = require('del')
const gulp = require('gulp')
const purgecss = require('gulp-purgecss')
var watch = false
gulp.task('clean', () => {
return del(['static'])
})
gulp.task('assets', () => {
return gulp
.src(['src/**/*', '!src/**/*.min.css'])
.pipe(gulp.dest('static'))
})
// Extractor from https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css-with-purgecss
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g)
}
}
gulp.task('purgecss', function() {
var pipe = gulp.src('src/**/*.min.css')
if (!watch) {
pipe = pipe.pipe(
purgecss({
content: ['src/*.html'],
extractors: [
{
extractor: TailwindExtractor,
extensions: ['html']
}
]
})
)
}
return pipe.pipe(gulp.dest('static/'))
})
gulp.task('watch', () => {
watch = true
gulp.watch(['src/**/*'], gulp.parallel('assets', 'purgecss'))
})
gulp.task('default', gulp.series('clean', gulp.parallel('assets', 'purgecss')))