-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
83 lines (72 loc) · 2.27 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
var cleancss = require("gulp-clean-css");
var gulp = require("gulp");
var htmlmin = require("gulp-htmlmin");
var sass = require("gulp-sass");
var uglify = require("gulp-uglify");
var uncss = require("gulp-uncss");
var csscleanOptions = {
level: {
1: {
specialComments: "none"
}
}
}
var htmlminOptions = {
collapseWhitespace: true,
minifyJS: true,
removeComments: true
}
var uglifyOptions = {
mangle: {
toplevel: true
}
}
var uncssOptions = {
html: ["./dist/**/*.html"]
}
// Remove unused CSS rules and minimize the CSS file.
gulp.task("clean-css", ["css"], function() {
return gulp.src("./dist/css/*.css")
.pipe(uncss(uncssOptions))
.pipe(cleancss(csscleanOptions))
.pipe(gulp.dest("./dist/css"));
});
// Convert Sass files to CSS and copy them to distribution directory.
gulp.task("css", function() {
return gulp.src("./stylesheets/kmbmpdc.scss")
.pipe(sass().on("error", sass.logError))
.pipe(gulp.dest("./dist/css"));
});
// Minimize HTML pages and copy them to distribution directory.
gulp.task("html", function() {
return gulp.src("./source/**/*.html")
.pipe(htmlmin(htmlminOptions))
.pipe(gulp.dest("./dist/"));
});
// Minimize Javascript and copy it over to distribution directory.
gulp.task("js", function() {
return gulp.src("./javascript/*.js")
.pipe(uglify(uglifyOptions))
.pipe(gulp.dest("./dist/js"))
});
// Copy over static assets to distribution directory.
gulp.task("static-assets", function() {
return gulp.src("./static/**/*")
.pipe(gulp.dest("./dist/static"))
});
// Perform all watch tasks.
gulp.task("watch", ["watch-css", "watch-html", "watch-js"]);
// Watch Sass files for changes and run "css" task.
gulp.task("watch-css", function() {
return gulp.watch("stylesheets/*.scss", ["css"]);
});
// Watch HTML files for changes and run "html" task.
gulp.task("watch-html", function() {
return gulp.watch("source/**/*.html", ["html"]);
});
// Watch JS files for changes and run "js" task.
gulp.task("watch-js", function() {
return gulp.watch("javascript/**/*.js", ["js"]);
});
// Perform all the tasks required for building the page(s).
gulp.task("default", ["css", "html", "js", "clean-css", "static-assets"]);