-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
76 lines (66 loc) · 1.95 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
const { watch, series, dest, src } = require("gulp");
const browserSync = require("browser-sync").create();
const sass = require("gulp-sass")(require("sass"));
const cleanCss = require("gulp-clean-css");
const purgecss = require("gulp-purgecss");
const concat = require("gulp-concat");
const minify = require("gulp-minify");
function copyHtml() {
return src(["./src/*.html"]).pipe(dest("./dist"));
}
function compileSass() {
return src("./src/scss/*.scss")
.pipe(sass().on("error", sass.logError))
.pipe(dest("./src/css/"));
}
function devPackCSS() {
return src("./src/css/*.css")
.pipe(concat("style.css"))
.pipe(dest("./dist/assets/css/"));
}
function packCSS() {
return src("./src/css/*.css")
.pipe(concat("style.css"))
.pipe(cleanCss())
.pipe(
purgecss({
content: ["./dist/**/*.html", "./dist/**/*.js"],
})
)
.pipe(dest("./dist/assets/css/"));
}
function packJs() {
return src(["./src/js/*.js"])
.pipe(concat("style.js"))
.pipe(minify({ ext: { min: ".min.js" }, noSource: true }))
.pipe(dest("./dist/assets/js"));
}
function packJsMain() {
//.pipe(concat('index.js'))
return src(["./src/js_main/*.js"])
.pipe(minify({ ext: { min: ".min.js" }, noSource: true }))
.pipe(dest("./dist/assets/js"));
}
// Serve from browserSync server
function browsersyncServe(cb) {
browserSync.init({
watch: true,
server: "./dist",
});
cb();
}
function browsersyncReload(cb) {
browserSync.reload();
cb();
}
// Watch Files & Reload browser after tasks
function watchTask() {
watch("./src/scss/*.scss", compileSass);
watch("./src/css/*.css", devPackCSS);
watch("./src/js_main/*.js", packJsMain);
watch(["./dist/assets/css/*.css", "./dist/assets/js/*.js", "./dist/*.*"],browsersyncReload);
}
// Default Gulp Task
exports.default = series(browsersyncServe, watchTask);
exports.toProduction = series(packCSS);
exports.init = series(copyHtml, compileSass, devPackCSS, packJs, packJsMain);