This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
gulpfile.mjs
220 lines (181 loc) · 4.68 KB
/
gulpfile.mjs
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// --- Gulp ---
import gulp from 'gulp';
// --- Configuration ---
import config from './bricks.config.mjs';
// --- Plugins ---
// CSS
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import purgecss from 'gulp-purgecss';
import cleancss from 'gulp-clean-css';
// JS
import rollup from '@rbnlffl/gulp-rollup';
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import terser from 'gulp-terser';
// Images
import imagemin from 'gulp-imagemin';
// Fonts
import ttf2woff2 from 'gulp-ttf2woff2';
// Icons
import faMinify from 'gulp-fa-minify';
// i18n
import checktextdomain from 'gulp-checktextdomain';
import wpPot from 'gulp-wp-pot';
// Utils
import rename from 'gulp-rename';
import gulpif from 'gulp-if';
import { deleteAsync } from 'del';
import sourcemaps from 'gulp-sourcemaps';
import environments from 'gulp-environments';
// Browser
import cache from 'gulp-cache';
import browserSync from 'browser-sync';
// Consts
const { src, dest, watch, series, parallel } = gulp;
const sass = gulpSass(dartSass);
const development = environments.development;
const production = environments.production;
// --- CSS ---
function css () {
return src(config.css.src)
.pipe(development(sourcemaps.init()))
.pipe(sass({
quietDeps: true
}).on('error', sass.logError))
.pipe(autoprefixer({
cascade: false
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(production(gulpif(config.enable.purgecss, purgecss({
content: config.css.content,
skippedContentGlobs: config.css.exclude,
safelist: config.cssSafelist
}))))
.pipe(production(cleancss()))
.pipe(development(sourcemaps.write('./')))
.pipe(dest(config.css.dist))
.pipe(browserSync.stream());
};
// --- JS ---
function js (done) {
src(config.js.src)
.pipe(development(sourcemaps.init()))
.pipe(rollup({
plugins: [
babel({ babelHelpers: 'bundled' }),
commonjs(),
nodeResolve()
]
}, { format: 'umd' }))
.pipe(production(terser({
format: {
comments: false
}
})))
.pipe(rename({
suffix: '.min'
}))
.pipe(development(sourcemaps.write('./')))
.pipe(dest(config.js.dist))
.pipe(browserSync.stream());
done();
};
// --- Images ---
function img () {
return src(config.img.src)
.pipe(imagemin({
// verbose: true
}))
.pipe(dest(config.img.dist))
.pipe(browserSync.stream());
};
// --- Fonts ---
function fonts (done) {
src(config.fonts.src.ttf)
.pipe(ttf2woff2({
ignoreExt: true
}))
.pipe(dest(config.fonts.dist))
.pipe(browserSync.stream());
src(config.fonts.src.woff)
.pipe(dest(config.fonts.dist))
.pipe(browserSync.stream());
done();
};
// --- Icons ---
function icons () {
return src(config.icons.src)
.pipe(rename('fontawesome.min.js'))
.pipe(production(faMinify(config.faIconSafelist)))
.pipe(production(terser({
format: {
comments: false
}
})))
.pipe(dest(config.js.dist));
};
// --- i18n ---
function domain () {
return src(config.php.watch)
.pipe(checktextdomain({
text_domain: config.textdomain,
keywords: config.i18n.functions,
correct_domain: true
}));
};
function pot () {
return src(config.php.watch)
.pipe(wpPot({
domain: config.textdomain
}))
.pipe(dest(config.i18n.dist + 'template.pot'));
};
// --- Utils ---
function setDev (done) {
environments.current(development);
done();
};
function setProd (done) {
environments.current(production);
done();
};
function clean () {
return deleteAsync('dist/**', { force: true });
};
// --- Browser ---
function bsInit (done) {
browserSync.init({
open: false,
injectChanges: true,
proxy: config.siteURL
});
done();
};
function bsReload (done) {
browserSync.reload();
done();
};
function clearCache (done) {
cache.clearAll();
done();
};
function watchFiles (done) {
watch(config.css.watch, series(css, clearCache, bsReload));
watch(config.js.watch, series(js, clearCache, bsReload));
watch(config.php.watch, series(clearCache, bsReload));
watch(config.img.watch, series(img, clearCache, bsReload));
watch(config.fonts.watch, series(fonts, clearCache, bsReload));
done();
};
// --- Tasks ---
const i18n = series(domain, pot);
const dev = series(setDev, clean, parallel(css, js, img, fonts, icons));
const build = series(setProd, clean, parallel(css, js, img, fonts, icons, i18n));
const watcher = parallel(bsInit, watchFiles);
export { css, js, img, fonts, icons, i18n, dev, build, watcher as watch };
export default dev;