This repository has been archived by the owner on Dec 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
88 lines (78 loc) · 1.93 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
85
86
87
88
/*! basestrap */
// Packages
const { src, dest, series, watch } = require("gulp");
const autoprefixer = require("autoprefixer");
const browserSync = require("browser-sync").create();
const cleanCSS = require("gulp-clean-css");
const del = require("del");
const filter = require("gulp-filter");
const postcss = require("gulp-postcss");
const rename = require("gulp-rename");
const sass = require("gulp-sass")(require("node-sass"));
const sourcemaps = require("gulp-sourcemaps");
// Remove pre-existing content from output folders
const cleanDist = (cb) => {
del.sync(["dist/"]);
return cb();
};
// Compile, autoprefix & minify SASS files
function buildStyles() {
return src("./scss/basestrap.scss")
.pipe(sourcemaps.init())
.pipe(
sass({
includePaths: "./node_modules",
outputStyle: "expanded",
}).on("error", function (err) {
sass.logError(err);
this.emit("end");
})
)
.pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write("."))
.pipe(dest("./dist"))
.pipe(filter("**/*.css"))
.pipe(
cleanCSS({
level: {
1: {
specialComments: 0,
},
},
})
)
.pipe(
rename({
suffix: ".min",
})
)
.pipe(sourcemaps.write("."))
.pipe(dest("./dist"));
}
// Watch for changes to the source directory
const serveDocs = (cb) => {
browserSync.init({
server: {
baseDir: "./",
},
});
cb();
};
// Reload the browser when files change
const reloadBrowser = (cb) => {
browserSync.reload();
cb();
};
// Watch all file changes
const watchSource = () => {
watch("./scss/**/*.scss", series(buildStyles, reloadBrowser));
watch("./index.html", reloadBrowser);
};
// Clean task
exports.clean = cleanDist;
// Build task
exports.build = buildStyles;
// Watch Task
exports.watch = watchSource;
// Default task
exports.default = series(cleanDist, series(this.build, serveDocs, watchSource));