-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
61 lines (56 loc) · 1.41 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
// Initialize modules
const { src, dest, watch, series } = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const babel = require("gulp-babel");
const terser = require("gulp-terser");
const browsersync = require("browser-sync").create();
const purgecss = require("gulp-purgecss");
// Sass Task
function scssTask() {
return (
src("app/scss/style.scss", { sourcemaps: true })
.pipe(sass())
//.pipe(purgecss({ content: ["*.html"] })) // remove unused codes from css
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(dest("dist", { sourcemaps: "." }))
);
}
// JavaScript Task
function jsTask() {
return src("app/js/script.js", { sourcemaps: true })
.pipe(babel({ presets: ["@babel/preset-env"] }))
.pipe(terser())
.pipe(dest("dist", { sourcemaps: "." }));
}
// Browsersync
function browserSyncServe(cb) {
browsersync.init({
server: {
baseDir: ".",
},
notify: {
styles: {
top: "auto",
bottom: "0",
},
},
});
cb();
}
function browserSyncReload(cb) {
browsersync.reload();
cb();
}
// Watch Task
function watchTask() {
watch("*.html", browserSyncReload);
watch(
["app/scss/**/*.scss", "app/**/*.js"],
series(scssTask, jsTask, browserSyncReload)
);
}
// Default Gulp Task
exports.default = series(scssTask, jsTask, browserSyncServe, watchTask);