-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
66 lines (59 loc) · 1.64 KB
/
Copy pathgulpfile.js
File metadata and controls
66 lines (59 loc) · 1.64 KB
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
var gulp = require("gulp");
var uglify = require("gulp-uglify");
var minifyCss = require("gulp-minify-css");
var htmlmin = require("gulp-htmlmin");
var browserSync = require("browser-sync").create();
var useref = require("gulp-useref");
var gulpIf = require("gulp-if");
var imagemin = require("gulp-imagemin");
var cache = require("gulp-cache");
var del = require("del");
gulp.task("css", function (done) {
gulp
.src("src/**/*.css")
.pipe(minifyCss({ keepSpecialComments: 0 }))
.pipe(gulp.dest("css/"));
done();
});
gulp.task("images", function (done) {
gulp
.src("src/images/**/*.+(png|jpg|svg)")
.pipe(cache(imagemin()))
.pipe(gulp.dest("images"));
done();
});
gulp.task("useref", function (done) {
gulp
.src("src/**/*.html")
.pipe(useref())
.pipe(gulpIf("*.js", uglify()))
.pipe(gulpIf("*.css", minifyCss({ keepSpecialComments: 0 })))
.pipe(
gulpIf(
"*.html",
htmlmin({
removeComments: true,
collapseWhitespace: true,
ignoreCustomFragments: [/<%[\s\S]*?%>/, /<\?[=|php]?[\s\S]*?\?>/],
})
)
)
.pipe(gulp.dest("./"));
done();
});
gulp.task("clean", function (done) {
del.sync(["./css", "./index.html", "./js", "./images"]);
done();
});
gulp.task("watch", function () {
browserSync.init({
server: {
baseDir: "./src",
},
});
gulp.watch("src/**/*.css").on("change", browserSync.reload);
gulp.watch("src/index.html").on("change", browserSync.reload);
gulp.watch("src/**/*.js").on("change", browserSync.reload);
});
gulp.task("default", gulp.series("watch"));
gulp.task("build", gulp.series("clean", "useref", "images"));