-
Notifications
You must be signed in to change notification settings - Fork 0
/
_dev.js
89 lines (78 loc) · 1.74 KB
/
_dev.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
const { src, dest, series, parallel, watch } = require('gulp');
const babel = require('gulp-babel');
const postcss = require('gulp-postcss');
const postcssVars = require('postcss-simple-vars');
const autoprefixer = require('autoprefixer');
const inject = require('gulp-inject');
const connect = require('gulp-connect');
const del = require('del');
const {
DEV_BUILDS,
GLOBAL_SOURCE,
CSS_SOURCE,
JS_SOURCE,
HTML_SOURCE,
CSS_BUILDS,
JS_BUILDS,
HTML_BUILDS,
} = require('./_filepaths');
const javascript = () =>
src(JS_SOURCE)
.pipe(babel({
presets: ['@babel/env'],
}))
.pipe(dest(DEV_BUILDS))
.pipe(connect.reload());
const styles = () =>
src(CSS_SOURCE)
.pipe(postcss([
postcssVars(),
autoprefixer({
browsers: ['last 5 version'],
}),
]))
.pipe(dest(DEV_BUILDS))
.pipe(connect.reload());
const copyHtml = () =>
src(HTML_SOURCE)
.pipe(dest(DEV_BUILDS));
const injectHtml = () =>
src(HTML_BUILDS)
.pipe(
inject(
src(
[ JS_BUILDS, CSS_BUILDS ],
{ read: false },
),
{
relative: true,
removeTags: true,
},
),
)
.pipe(dest(DEV_BUILDS))
.pipe(connect.reload());
const html = series(copyHtml, injectHtml);
const server = () => connect.server({
root: DEV_BUILDS,
livereload: true,
});
const watcher = () => {
watch([CSS_SOURCE], styles);
watch([JS_SOURCE], javascript);
watch([HTML_SOURCE], html);
};
const cleanup = () => del(DEV_BUILDS);
exports.javascript = javascript;
exports.styles = styles;
exports.html = html;
exports.server = server;
exports.watcher = watcher;
exports.cleanup = cleanup;
exports.default = finishCb =>
series(
cleanup,
parallel(javascript, styles),
html,
parallel(server, watcher)
)(finishCb);