-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
76 lines (65 loc) · 1.65 KB
/
gulpfile.js
File metadata and controls
76 lines (65 loc) · 1.65 KB
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
const {
src,
dest,
watch,
series
} = require('gulp');
const tailwindcss = require('tailwindcss');
const postcss = require('gulp-postcss'); // CSS preprocessor
// PostCSS Plugins
const purgecss = require('@fullhuman/postcss-purgecss'); // removes unused classes
const autoprefixer = require('autoprefixer'); // adds vendor prefixes to CSS rules using https://caniuse.com
const cssnano = require('cssnano'); // minifies css
const path = {
html: './index.html',
css: './src/styles.css',
config: './src/tailwind.config.js',
dev: './resources/css/',
prod: './dist/css/'
};
/**
* Custom PurgeCSS Extractor
* https://github.com/FullHuman/purgecss
*/
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g);
}
}
function buildDev() {
let plugins = [
tailwindcss(path.config),
autoprefixer
];
return src(path.css)
.pipe(postcss(plugins))
.pipe(dest(path.dev));
}
function watchTailwind() {
watch(path.css, buildDev);
watch(path.config, buildDev);
}
function build() {
let cssnanoConfig = {
preset: 'default'
};
let purgecssConfig = {
content: [path.html],
extractors: [{
extractor: TailwindExtractor,
extensions: ["html", "js"]
}]
};
let plugins = [
tailwindcss(path.config),
purgecss(purgecssConfig),
autoprefixer,
cssnano(cssnanoConfig)
];
return src(path.css)
.pipe(postcss(plugins))
.pipe(dest(path.prod));
}
exports.default = series(buildDev, watchTailwind);
exports.dev = buildDev;
exports.build = build;