This repository has been archived by the owner on Nov 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
264 lines (244 loc) · 8.02 KB
/
gulpfile.babel.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import autoprefixer from "autoprefixer";
import browserSync from "browser-sync";
import del from "del";
import gulp from "gulp";
import concat from "gulp-concat";
import connect from "gulp-connect";
import csso from "gulp-csso";
import data from "gulp-data";
import flatten from "gulp-flatten";
import imagemin from "gulp-imagemin";
import plumber from "gulp-plumber";
import postcss from "gulp-postcss";
import jade from "gulp-jade";
import rollup from "gulp-rollup";
import sass from "gulp-sass";
import sourcemaps from "gulp-sourcemaps";
import watch from "gulp-watch";
import path from "path";
import remember from "gulp-remember";
import rename from "gulp-rename";
import newer from "gulp-newer";
import gulpIf from "gulp-if";
import debug from "gulp-debug";
import notify from "gulp-notify";
import htmltidy from "gulp-htmltidy";
import stylelint from "gulp-stylelint";
import svgmin from "gulp-svgmin";
import svgstore from "gulp-svgstore";
import buble from "rollup-plugin-buble";
import eslint from "rollup-plugin-eslint";
import nodeResolve from "rollup-plugin-node-resolve";
import uglify from "rollup-plugin-uglify";
import commonjs from "rollup-plugin-commonjs";
gulp.task("assets", gulp.parallel(_root, _assets, _images, _svg, _fonts));
gulp.task("jade", gulp.series(_jade));
gulp.task("sass", gulp.parallel(_sass));
gulp.task("js", _js);
gulp.task("other", gulp.series(_icons_sprite));
gulp.task("clean", _clean);
gulp.task("build", gulp.series("clean", gulp.parallel("jade", "sass", "js", "assets", "other")));
gulp.task("watch", _watch);
gulp.task("serve", gulp.series("build", _serve, "watch"));
gulp.task("connect", _connect);
gulp.task("default", gulp.series("build"));
const options = {
plumber: function(title = "Untitled") {
return {
errorHandler: notify.onError(function (error) {
return {
title: `${title}: Error Handled`,
message: error.message
}
})
}
},
postcss: {
plugins: [
autoprefixer({ browsers: ["last 2 versions"]})
]
}
};
function _clean(done) {
del.sync(["./build/", "!./build/.git/"]);
done();
}
function _serve() {
browserSync({
server: {
baseDir: "./build/"
}
});
browserSync.watch("./build/**/*.*").on("change", browserSync.reload);
}
function _connect(done) {
connect.server({
root: "./build/",
livereload: true
});
done();
}
function _watch() {
gulp.watch("./src/**/*.jade", gulp.series("jade"));
gulp.watch("./src/**/*.{sass,scss}", gulp.series("sass"));
gulp.watch("./src/**/*.js", gulp.series("js"));
gulp.watch("./src/**/assets/images/*.svg", _svg);
gulp.watch("./src/**/assets/images/*.{jpg,jpeg,png}", _images);
gulp.watch("./src/**/assets/fonts/*", _fonts);
gulp.watch("./src/components/icon/assets/svg/*.svg", gulp.series("other"));
}
function _jade() {
return gulp.src(["./src/pages/*/*.jade", "!./src/pages/*/_*.jade"])
.pipe(plumber(options.plumber("Jade")))
.pipe(jade({
pretty: true,
locals: {
getData: function(component, file) {
try {
return require(`./src/components/${component}/${file}`);
}
catch (e) {
return null;
}
}
}
}))
.pipe(htmltidy({
dropEmptyElements: false,
tabSize: 2,
indentSpaces: 2,
indent: "auto",
wrap: 0
}))
.pipe(flatten())
.pipe(gulp.dest("./build/"))
}
function _sass() {
return gulp.src(["./src/pages/*/*.sass", "!./src/pages/*/_*.sass"])
.pipe(plumber(options.plumber("Sass")))
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(stylelint({
reporters: [{formatter: "verbose", console: true}]
}))
.pipe(postcss(options.postcss.plugins))
.pipe(csso({ restructure: false }))
.pipe(sourcemaps.write("."))
.pipe(flatten())
.pipe(gulp.dest("./build/"))
}
function _js() {
return gulp.src(["./src/pages/*/*.js", "!./src/pages/*/_*.js"], { read: false })
.pipe(plumber(options.plumber("Js")))
.pipe(rollup({
sourceMap: true,
format: "iife",
plugins: [
eslint({
envs: ["browser", "node", "es6"],
fix: true,
parser: "babel-eslint"
}),
nodeResolve({
browser: true,
extensions: [ '.js', '.json' ],
preferBuiltins: false
}),
commonjs(),
buble(),
uglify()
]
}))
.pipe(sourcemaps.write("."))
.pipe(flatten())
.pipe(gulp.dest("./build/"))
}
function _images() {
return gulp.src("./src/**/assets/images/*.{jpg,jpeg,png}", {since: gulp.lastRun("assets")})
.pipe(plumber(options.plumber("Images")))
.pipe(flatten())
.pipe(newer("./build/assets/images/"))
//.pipe(debug({title: "images"}))
.pipe(imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest("./build/assets/images/"))
}
function _svg() {
return gulp.src("./src/**/assets/images/*.svg", {since: gulp.lastRun("assets")})
.pipe(plumber(options.plumber("Svg")))
.pipe(flatten())
.pipe(newer("./build/assets/images/"))
.pipe(debug({title: "svg"}))
.pipe(gulp.dest("./build/assets/images/"))
}
function _fonts() {
return gulp.src("./src/**/assets/fonts/*.{woff,woff2}", {since: gulp.lastRun("assets")})
.pipe(plumber(options.plumber("Fonts")))
.pipe(flatten())
.pipe(newer("./build/assets/fonts/"))
//.pipe(debug({title: "fonts"}))
.pipe(gulp.dest("./build/assets/fonts/"))
}
function _assets() {
return gulp.src("./src/assets/**/*.*", {since: gulp.lastRun("assets")})
.pipe(plumber(options.plumber("Assets")))
.pipe(newer("./build/assets/"))
//.pipe(debug({title: "assets"}))
.pipe(gulp.dest("./build/assets/"))
}
function _root() {
return gulp.src("./src/*.*", {since: gulp.lastRun("assets")})
.pipe(plumber(options.plumber("Root")))
.pipe(newer("./build/"))
//.pipe(debug({title: "root"}))
.pipe(gulp.dest("./build/"))
}
function _icons_sprite() {
return gulp.src("./src/components/icon/assets/svg/*.svg", {since: gulp.lastRun("other")})
.pipe(plumber(options.plumber("icons_sprite")))
.pipe(newer("./build/assets/svg/"))
.pipe(svgmin({
plugins: [
{
cleanupNumericValues: {
floatPrecision: 2
}
}, {
convertColors: {
names2hex: true,
rgb2hex: true
}
}, {
cleanupAttrs: true
}, {
removeEditorsNSData: true
}, {
convertTransform: true
}, {
convertPathData: true
}, {
removeUnknownsAndDefaults: true
}, {
removeRasterImages: true
}, {
mergePaths: true
}, {
transformsWithOnePath: true
}, {
removeDimensions: true
}, {
removeStyleElement: true
}, {
removeAttrs: {
attrs: [ "fill", "stroke", "data-name", "id", "class" ]
}
}
]
}))
.pipe(rename({prefix: 'icon-'}))
.pipe(svgstore())
.pipe(rename({basename: 'icons-sprite'}))
.pipe(gulp.dest("./build/assets/svg/"))
}