-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.mjs
79 lines (70 loc) · 1.88 KB
/
gulpfile.mjs
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
import gulp from "gulp";
import imagemin from "gulp-imagemin";
import uglify from "gulp-uglify";
import minify from "gulp-htmlmin";
import sass from "sass";
import gSass from "gulp-sass";
import handlebars from "gulp-compile-handlebars";
import rename from "gulp-rename";
const pipSass = gSass(sass);
const copyHandlebars = () =>
gulp
.src(
["404", "index", "contact", "portfolio", "resume", "pdf"].map(
(file) => `./src/handlebars/${file}.handlebars`
)
)
.pipe(
handlebars(
{},
{
ignorePartials: true,
batch: ["./src/handlebars/partials"],
}
)
)
.pipe(
rename((path) => {
path.extname = ".html";
})
)
.pipe(gulp.dest("dist/html"));
// Compile Sass
const compileSass = () =>
gulp
.src("src/sass/index.scss")
//todo have to log the error right
.pipe(pipSass())
.pipe(gulp.dest("dist/css"));
//move the rest of file from src to dist
const move = () =>
gulp
.src(
["svg", "webp", "gif", "jpg", "png", "js"].map((ext) => `src/**/*.${ext}`)
)
.pipe(gulp.dest("dist"));
// Optimize html and css
const minifyDist = () =>
gulp
.src(["html", "svg", "css"].map((ext) => "./dist/**/*." + ext))
.pipe(minify({ collapseWhitespace: true, removeComments: true }))
.pipe(gulp.dest("dist"));
// Optimize Images
const imageMin = () =>
gulp
.src(["webp", "gif", "jpg", "png"].map((ext) => "./dist/img/**/*." + ext))
.pipe(imagemin())
.pipe(gulp.dest("dist/img"));
// export tasks
export const build = gulp.series(copyHandlebars, compileSass, move);
export const buildForProduction = gulp.series(
build,
minifyDist,
imageMin,
move
);
export const watch = gulp.series(function () {
gulp.watch("./src/**/*.scss", compileSass);
gulp.watch("./src/**/*.handlebars", copyHandlebars);
gulp.watch("./src/**/*.!(handlebars|scss)", move);
});