-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
84 lines (74 loc) · 1.92 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
const { src, dest, series, parallel } = require("gulp");
const concat = require("gulp-concat");
const browsersync = require("browser-sync").create();
const clean = require("gulp-clean");
const watch = require("gulp-watch");
const cleanCSS = require("gulp-clean-css");
const uglify = require("gulp-uglify");
const pipeline = require("readable-stream").pipeline;
const path = {
src: {
html: "./src/index.html",
css: "./src/*.css",
js: [
"./src/script/const.js",
"./src/script/api.js",
"./src/script/collection.js",
"./src/script/view/albums-view.js",
"./src/script/view/stickers-view.js",
"./src/script/controller.js",
"./src/script/app.js",
],
},
dist: {
baseDir: "./dist",
css: "main.css",
js: "app.js",
},
};
function copyHtml() {
return src(path.src.html)
.pipe(dest(path.dist.baseDir))
.pipe(browsersync.stream());
}
function copyCss() {
return src(path.src.css)
.pipe(concat(path.dist.css))
.pipe(cleanCSS({ compatibility: "ie8" }))
.pipe(dest(path.dist.baseDir))
.pipe(browsersync.stream());
}
function copyJs() {
return pipeline(
src(path.src.js).pipe(concat(path.dist.js)),
uglify(),
dest(path.dist.baseDir)
);
}
function browserSync() {
browsersync.init({
server: {
baseDir: path.dist.baseDir,
},
port: 3000,
notify: false,
});
}
function cleanDist() {
return src(path.dist.baseDir, { read: false, allowEmpty: true }).pipe(
clean()
);
}
function watchFiles() {
watch(path.src.html, { ignoreInitial: false }, copyHtml);
watch(path.src.css, { ignoreInitial: false }, copyCss);
watch(path.src.js, { ignoreInitial: false }, copyJs);
}
function buildTask() {
return series(cleanDist, parallel(copyHtml, copyCss, copyJs));
}
function startTask() {
return series(buildTask(), parallel(watchFiles, browserSync));
}
module.exports.build = buildTask();
module.exports.start = startTask();