-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·160 lines (141 loc) · 3.43 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var gulp = require("gulp");
var sass = require("gulp-sass");
var cleanCSS = require("gulp-clean-css");
var autoprefixer = require("gulp-autoprefixer");
var rename = require("gulp-rename");
var uglify = require("gulp-uglify");
var imagemin = require("gulp-imagemin");
var htmlmin = require("gulp-htmlmin");
var browserSync = require("browser-sync").create();
var clean = require("gulp-clean");
var deploy = require("gulp-gh-pages");
/**
* Push build to gh-pages
*/
gulp.task("deploy", function () {
return gulp.src("./dist/**/*").pipe(deploy());
});
// plugin for lossy jpg compression
var imageminMozjpeg = require("imagemin-mozjpeg");
// Compile SCSS
gulp.task("css:compile", function () {
return gulp
.src("./src/scss/**/*.scss")
.pipe(
sass
.sync({
outputStyle: "expanded",
})
.on("error", sass.logError)
)
.pipe(
autoprefixer({
browsers: ["last 4 versions"],
})
)
.pipe(cleanCSS())
.pipe(
rename({
suffix: ".min",
})
)
.pipe(gulp.dest("./dist/css"))
.pipe(browserSync.stream());
});
gulp.task("css:copy", function () {
return gulp.src("./src/scss/*.css").pipe(gulp.dest("./dist/css"));
});
// CSS
gulp.task("css", ["css:compile"]);
// Minify JavaScript
gulp.task("js:minify", function () {
return gulp
.src(["./src/js/*.js", "!./src/js/*.min.js"])
.pipe(uglify())
.pipe(
rename({
suffix: ".min",
})
)
.pipe(gulp.dest("./dist/js"))
.pipe(browserSync.stream());
});
// JS
gulp.task("js", ["js:minify"]);
// Task to copy files and assets
// Optimize images
gulp.task("copy:images", function () {
return gulp
.src("./src/img/**/*")
.pipe(
imagemin([
imageminMozjpeg({
quality: 90,
}),
imagemin.gifsicle(),
imagemin.optipng(),
imagemin.svgo(),
])
)
.pipe(gulp.dest("./dist/img"));
});
gulp.task("copy:favicons", function () {
return gulp
.src("./src/favicons/*")
.pipe(imagemin())
.pipe(gulp.dest("./dist/favicons"));
});
gulp.task("copy:files", function () {
return gulp
.src([
"./src/*.*",
"./src/*/*.woff",
"./src/*/*.min.css",
"./src/*/*.min.js",
"!./src/**/*.html",
])
.pipe(gulp.dest("./dist/"));
});
// Files
gulp.task("copy", ["copy:images", "copy:favicons", "copy:files"]);
gulp.task("html:minify", function () {
return gulp
.src("./src/**/*.html")
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest("./dist/"))
.pipe(browserSync.stream());
});
gulp.task("html", ["html:minify"]);
// Configure the browserSync task
gulp.task("browserSync", ["build"], function () {
browserSync.init({
server: {
baseDir: "./dist",
},
port: "8080",
});
});
// Clean /dist
gulp.task("clean", function () {
return gulp.src("dist", { read: false }).pipe(clean());
});
// Dev task without copying
gulp.task("serve", ["css", "js", "html"], function () {
gulp.watch("./src/scss/*.scss", ["css"]);
gulp.watch("./src/js/*.js", ["js"]);
gulp.watch("./src/**/*.html", ["html"]);
browserSync.init({
server: {
baseDir: "./dist",
},
port: "8080",
});
});
// Build task
gulp.task("build", ["css", "js", "copy", "html"]);
// Dev task
gulp.task("default", ["build", "browserSync"], function () {
gulp.watch("./src/scss/*.scss", ["css"]);
gulp.watch("./src/js/*.js", ["js"]);
gulp.watch("./src/**/*.html", ["html"]);
});