-
Notifications
You must be signed in to change notification settings - Fork 0
/
_prod.js
93 lines (81 loc) · 1.91 KB
/
_prod.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
92
93
const { src, dest, series, parallel } = 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 del = require('del');
const uglify = require('gulp-uglify');
const cssnano = require('cssnano');
const hash = require('gulp-hash-filename');
var git = require('gulp-git');
const {
GLOBAL_BUILDS,
CSS_SOURCE,
JS_SOURCE,
HTML_SOURCE,
CSS_PROD_BUILDS,
JS_PROD_BUILDS,
HTML_PROD_BUILDS,
} = require('./_filepaths');
const HASHING_OPTIONS = {
format: '{name}.{hash}{ext}'
};
const javascript = () =>
src(JS_SOURCE)
.pipe(babel({
presets: ['@babel/env'],
}))
.pipe(uglify())
.pipe(hash(HASHING_OPTIONS))
.pipe(dest(GLOBAL_BUILDS));
const styles = () =>
src(CSS_SOURCE)
.pipe(postcss([
postcssVars(),
autoprefixer({
browsers: ['last 5 version'],
}),
cssnano(),
]))
.pipe(hash(HASHING_OPTIONS))
.pipe(dest(GLOBAL_BUILDS));
const copyHtml = () =>
src(HTML_SOURCE)
.pipe(dest(GLOBAL_BUILDS));
const injectHtml = () =>
src(HTML_PROD_BUILDS)
.pipe(
inject(
src(
[
CSS_PROD_BUILDS,
JS_PROD_BUILDS,
`!${GLOBAL_BUILDS}/_*.js`,
],
{ read: false },
),
{
relative: true,
removeTags: true,
},
),
)
.pipe(dest(GLOBAL_BUILDS))
const html = series(copyHtml, injectHtml);
const removeAssets = () => del([
CSS_PROD_BUILDS,
JS_PROD_BUILDS,
`!${GLOBAL_BUILDS}/_*.js`,
]);
const checkoutFiles = () => src(HTML_PROD_BUILDS).pipe(git.checkoutFiles());
const cleanup = finishCb => series(removeAssets, checkoutFiles)(finishCb);
exports.javascript = javascript;
exports.styles = styles;
exports.html = html;
exports.cleanup = cleanup;
exports.default = series(
cleanup,
parallel(javascript, styles),
html,
);