-
Notifications
You must be signed in to change notification settings - Fork 23
/
gulpfile.js
159 lines (142 loc) · 3.19 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
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
const { src, dest, series, parallel } = require('gulp');
const concat = require('gulp-concat');
const gzip = require('gulp-gzip');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const terser = require('gulp-terser');
const jsonminify = require('gulp-jsonminify');
const htmlmin = require('gulp-html-minifier-terser');
const replace = require('gulp-replace');
// Paths for tasks
let paths = {
styles: {
dest: 'data/static/',
bundles: {
'app.css': [
'src_data/styles/pico.min.css',
'src_data/styles/iconly.css',
'src_data/styles/app.css'
]
}
},
scripts: {
dest: 'data/static/',
bundles: {
'app.js': [
'src_data/scripts/i18n.min.js',
'src_data/scripts/lang.js',
'src_data/scripts/utils.js'
]
}
},
json: [
{
src: 'src_data/locales/*.json',
dest: 'data/static/locales/'
}
],
static: [
{
src: 'src_data/fonts/*.*',
dest: 'data/static/fonts/'
},
{
src: 'src_data/images/*.*',
dest: 'data/static/images/'
}
],
pages: {
src: 'src_data/pages/*.html',
dest: 'data/pages/'
}
};
// Tasks
const styles = (cb) => {
for (let name in paths.styles.bundles) {
const items = paths.styles.bundles[name];
src(items)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(postcss([
cssnano({ preset: 'advanced' })
]))
.pipe(concat(name))
.pipe(gzip({
append: true
}))
.pipe(dest(paths.styles.dest));
}
cb();
}
const scripts = (cb) => {
for (let name in paths.scripts.bundles) {
const items = paths.scripts.bundles[name];
src(items)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(terser().on('error', console.error))
.pipe(concat(name))
.pipe(gzip({
append: true
}))
.pipe(dest(paths.scripts.dest));
}
cb();
}
const jsonFiles = (cb) => {
for (let i in paths.json) {
const item = paths.json[i];
src(item.src)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(jsonminify())
.pipe(gzip({
append: true
}))
.pipe(dest(item.dest));
}
cb();
}
const staticFiles = (cb) => {
for (let i in paths.static) {
const item = paths.static[i];
src(item.src, { encoding: false })
.pipe(gzip({
append: true
}))
.pipe(dest(item.dest));
}
cb();
}
const pages = () => {
return src(paths.pages.src)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(htmlmin({
html5: true,
caseSensitive: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
conservativeCollapse: true,
removeComments: true,
minifyJS: true
}))
.pipe(gzip({
append: true
}))
.pipe(dest(paths.pages.dest));
}
exports.build_styles = styles;
exports.build_scripts = scripts;
exports.build_json = jsonFiles;
exports.build_static = staticFiles;
exports.build_pages = pages;
exports.build_all = parallel(styles, scripts, jsonFiles, staticFiles, pages);