-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
91 lines (80 loc) · 2.32 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
//@ts-check
const { src, dest, watch, parallel, series } = require('gulp');
const pug = require('gulp-pug');
const postcss = require('gulp-postcss');
const purgecss = require('gulp-purgecss');
const browserSync = require('browser-sync').create();
// Custom PurgeCSS extractor for Tailwind that allows special characters in
// class names.
//
// https://github.com/FullHuman/purgecss#extractor
class TailwindExtractor {
static extract(content) {
return content.match(/[A-Za-z0-9-_:\/]+/g) || [];
}
}
function cssTask() {
return src('src/**/*.css')
.pipe(postcss([
require('tailwindcss'),
require('postcss-preset-env')({
stage: 3,
features: {
'nesting-rules': true
}
})
]))
.pipe(dest('dist'))
.pipe(browserSync.stream());
}
// https://stackoverflow.com/questions/29793894/how-to-set-gulp-dest-in-same-directory-as-pipe-inputs
function htmlTask() {
return src(['src/**/*.pug'])
.pipe(pug())
.pipe(dest('dist'))
.pipe(browserSync.stream());
}
function browserSyncTask() {
browserSync.init({
server: {
baseDir: 'dist'
},
});
}
function buildCSS() {
return src('src/**/*.css')
.pipe(postcss([
require('tailwindcss'),
require('postcss-preset-env')({
features: {
'nesting-rules': true
}
}),
require('autoprefixer')({
cascade: false
})
]))
.pipe(purgecss({
content: ['src/**/*.pug', 'src/**/*.css'],
extractors: [
{
extractor: TailwindExtractor,
// Specify the file extensions to include when scanning for
// class names.
extensions: ['pug', 'css']
}
]
}))
.pipe(dest('dist'));
}
function buildHTML() {
return src(['src/**/*.pug'])
.pipe(pug())
.pipe(dest('dist'));
}
function watchFiles() {
watch('src/**/*.css', cssTask);
watch('src/**/*.pug', htmlTask);
}
exports.build = parallel(buildHTML, buildCSS);
exports.default = series(parallel(cssTask, htmlTask), parallel(browserSyncTask, watchFiles));