-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
100 lines (87 loc) · 2.57 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
//https://stackoverflow.com/questions/53573492/gulp-combining-tasks-into-default-command
var gulp = require("gulp");
var sass = require("gulp-sass");
var browserSync = require("browser-sync");
var jshint = require("gulp-jshint");
var concat = require("gulp-concat");
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var minifyHtml = require("gulp-minify-html");
var minifyCss = require("gulp-minify-css");
var imagemin = require("gulp-imagemin");
var jsonminify = require("gulp-jsonminify");
// this task works, even though you have no sass
gulp.task("sass", function() {
return gulp
.src("sass/**/*.scss")
.pipe(sass().on("error", sass.logError))
.pipe(gulp.dest("./css/")) //removed semicolon
.pipe(browserSync.reload({ stream: true }));
});
// Concatenate & Minify JS
gulp.task("scripts", function() {
return gulp
.src("js/*.js")
.pipe(uglify())
.pipe(gulp.dest("dist/js"));
});
// Concatenate & Minify JSON
gulp.task("jsonmin", function() {
return gulp
.src(["js/*.json"])
.pipe(jsonminify())
.pipe(gulp.dest("dist/js"));
});
gulp.task("imagemin", function() {
return gulp
.src("img/*")
.pipe(imagemin())
.pipe(gulp.dest("dist/img"));
});
gulp.task("minify-css", function() {
return gulp
.src("css/styles.css") // path to your file
.pipe(minifyCss())
.pipe(gulp.dest("dist/css"));
});
gulp.task("minify-html", function() {
return gulp
.src("*.html") // path to your files
.pipe(minifyHtml())
.pipe(gulp.dest("dist"));
});
gulp.task("lint", function() {
return gulp
.src("js/*.js")
.pipe(jshint())
.pipe(jshint.reporter("default"));
});
gulp.task("compcss", function() {
return gulp
.src("js/*.js")
.pipe(concat("all.js"))
.pipe(gulp.dest("dist"))
.pipe(rename("all.min.js"))
.pipe(uglify())
.pipe(gulp.dest("dist/js"));
});
// Watch Files For Changes
gulp.task("watch", function() {
gulp.watch("js/*.js", ["lint", "scripts"]);
gulp.watch("scss/*.scss", ["sass"]);
});
// Default Task
gulp.task("default", gulp.series(["lint", "sass", "scripts", "watch"]));
// watch Sass files for changes, run the Sass preprocessor with the 'sass' task and reload
gulp.task(
"serve",
gulp.series("scripts", function() {
browserSync({
server: {
baseDir: "./"
}
});
gulp.watch("js/*.js", browserSync.reload);
gulp.watch("index.html", browserSync.reload);
})
);