-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathgulpfile.mjs
93 lines (82 loc) · 1.85 KB
/
gulpfile.mjs
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
import {src, dest, watch, series, task, parallel} from "gulp";
import babel from "gulp-babel";
import cleanCSS from "gulp-clean-css";
import terser from "gulp-terser";
import rename from "gulp-rename";
import autoprefixer from "gulp-autoprefixer";
import headerComment from "gulp-header-comment";
import browserSync from "browser-sync";
const header = `
Accordion v3.4.0
<%= pkg.description %>
https://github.com/michu2k/Accordion
Copyright (c) <%= pkg.author %>
Published under <%= pkg.license %> License
`;
// Config
const config = {
srcCSS: "src/**/*.css",
distCSS: "dist",
srcJS: "src/**/*.js",
distJS: "dist"
};
// Server
function server() {
browserSync.init({
server: {
baseDir: "./"
}
});
}
// Server reload
function reload(done) {
browserSync.reload();
done();
}
// CSS
function compileCSS() {
return src(config.srcCSS)
.pipe(rename({suffix: ".min"}))
.pipe(autoprefixer({cascade: false}))
.pipe(cleanCSS())
.pipe(headerComment(header))
.pipe(dest(config.distCSS))
.pipe(browserSync.stream());
}
// Javascript
function compileJs() {
return src(config.srcJS)
.pipe(
babel({
presets: ["@babel/preset-env"],
retainLines: true
})
)
.on("error", function (error) {
console.log(error.toString());
this.emit("end");
})
.pipe(
terser({
ecma: 2020
})
)
.pipe(rename({suffix: ".min"}))
.pipe(headerComment(header))
.pipe(dest(config.distJS))
.pipe(browserSync.stream());
}
// Watch CSS files
function watchCSS() {
watch(config.srcCSS, series(compileCSS, reload));
}
// Watch Javascript files
function watchJs() {
watch(config.srcJS, series(compileJs, reload));
}
// Watch HTML files
function watchHtml() {
watch("*.html", series(reload));
}
// Main task
task("default", parallel(server, watchCSS, watchJs, watchHtml));