-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.js
122 lines (111 loc) · 2.63 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Plugins =============================================================
const gulp = require("gulp");
const pump = require("pump");
const rename = require("gulp-rename");
// Sync
const browserSync = require("browser-sync");
// HTML
const slim = require("gulp-slim");
const htmlmin = require("gulp-htmlmin");
// CSS
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");
const cssmin = require("gulp-cssmin");
// JS
const terser = require("gulp-terser");
const size = require("gulp-size");
// Browser Sync ========================================================
gulp.task("sync", function () {
return browserSync({
server: "",
});
});
// Refresh =============================================================
gulp.task("refresh", function () {
return gulp.src("*").pipe(
browserSync.reload({
stream: true,
})
);
});
// Compile HTML ========================================================
gulp.task("html", function () {
return gulp
.src("src/*.slim")
.pipe(
slim({
pretty: true,
})
)
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true,
})
)
.pipe(gulp.dest(""))
.pipe(
browserSync.reload({
stream: true,
})
);
});
// Compile CSS =========================================================
gulp.task("css", function () {
return gulp
.src("src/css/*.scss")
.pipe(sass())
.on("error", sass.logError)
.pipe(
autoprefixer({
browsers: ["last 2 versions"],
cascade: false,
})
)
.pipe(cssmin())
.pipe(
rename(function (path) {
path.basename += ".min";
path.extname = ".css";
})
)
.pipe(gulp.dest("css"))
.pipe(
browserSync.reload({
stream: true,
})
);
});
// JS ==================================================================
gulp.task("js", function () {
return gulp
.src("src/js/*.js")
.pipe(terser())
.pipe(
rename(function (path) {
path.basename += ".min";
path.extname = ".js";
})
)
.pipe(gulp.dest("js"))
.pipe(
size({
showFiles: true,
})
)
.pipe(
browserSync.reload({
stream: true,
})
);
});
// Watch ===============================================================
gulp.task("watch", ["sync"], function () {
gulp.watch("src/*.slim", ["html"]);
gulp.watch("src/js/*.js", ["js"]);
gulp.watch("src/css/*.scss", ["css"]);
});
// Default task ========================================================
gulp.task("default", ["watch"]);