-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
90 lines (81 loc) · 2.26 KB
/
Copy pathgulpfile.js
File metadata and controls
90 lines (81 loc) · 2.26 KB
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
const { src, dest, series, parallel, watch } = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const cssnano = require("gulp-cssnano");
const clean = require("gulp-clean");
const autoprefixer = require("gulp-autoprefixer");
const rename = require("gulp-rename");
const babel = require("gulp-babel");
const uglify = require("gulp-uglify");
const imagemin = require("gulp-imagemin");
const sourcemaps = require("gulp-sourcemaps");
const kit = require("gulp-kit");
const browserSync = require("browser-sync").create();
const reload = browserSync.reload;
const paths = {
html: "./html/**/*.kit",
sass: "./src/sass/**/*.scss",
js: "./src/js/**/*.js",
img: "./src/img/**/**",
dist: "./dist",
sassDest: "./dist/css",
jsDest: "./dist/js",
imgDest: "./dist/img",
};
function sassCompiler(done) {
src(paths.sass)
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(cssnano({ zindex: false }))
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write())
.pipe(dest(paths.sassDest));
done();
}
function javaScript(done) {
src(paths.js)
.pipe(sourcemaps.init())
.pipe(babel({ presets: ["@babel/env"] }))
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write())
.pipe(dest(paths.jsDest));
done();
}
function convertImages(done) {
src(paths.img).pipe(imagemin()).pipe(dest(paths.imgDest));
done();
}
function handleKits(done) {
src(paths.html).pipe(kit()).pipe(dest("./"));
done();
}
function cleanStuff(done) {
src(paths.dist, { read: false }).pipe(clean());
done();
}
function startBrowserSync(done) {
browserSync.init({ server: { baseDir: "./" } });
done();
}
function watchForChanges(done) {
watch("./*.html").on("change", reload);
watch(
[paths.html, paths.sass, paths.js],
parallel(handleKits, sassCompiler, javaScript)
).on("change", reload);
watch(paths.img, convertImages).on("change", reload);
done();
}
const mainFunctions = parallel(
handleKits,
sassCompiler,
javaScript,
convertImages
);
module.exports.default = series(
mainFunctions,
startBrowserSync,
watchForChanges
);
module.exports.cleanStuff = cleanStuff;