-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (74 loc) · 2.17 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
const { src, dest, watch, series, parallel } = require("gulp");
const browserSync = require('browser-sync');
const ejs = require('gulp-ejs');
const sass = require("gulp-sass")(require("sass"));
const webp = require('gulp-webp');
const rename = require('gulp-rename');
const uglify = require("gulp-uglify");
const htmlMin = require('gulp-htmlmin');
const prettify = require('gulp-prettify');
const browserSyncFunc = () => {
browserSync.init({
notify: false,
server: {
baseDir: 'dist',
},
startPath: './index.html',
reloadOnRestart: true,
});
};
const browserReloadFunc = (done) => {
browserSync.reload();
done();
};
const compileEjs = () =>
src(["src/ejs/**/*.ejs", '!' + "src/ejs/**/_*.ejs"])
.pipe(ejs({}, { ext: '.html'}))
.pipe(rename({
extname: '.html'
}))
.pipe(
htmlMin({
removeComments: false,
collapseWhitespace: false,
collapseInlineTagWhitespace: false,
preserveLineBreaks: false,
})
)
.pipe(
prettify({
indent_with_tabs: true,
indent_size: 2,
})
)
.pipe(dest("dist"));
const watchEjsFiles = () => watch("src/ejs/**/*.ejs", series(compileEjs, browserReloadFunc));
const compileSass = () =>
src("src/sass/main.sass")
.pipe(
sass({
outputStyle: "expanded"
})
)
.pipe(dest("dist/css"));
const watchSassFiles = () => watch("src/sass/**/*.sass", series(compileSass, browserReloadFunc));
const convertWebp = () =>
src("src/images/**/*.{jpg,png}")
.pipe(webp())
.pipe(dest("dist/images"));
const convertOtherImages = () =>
src("src/images/**/*.{gif,svg}")
.pipe(dest("dist/images"));
const watchImagesFiles = () => watch("src/images/**/*.{jpg,png,gif,svg}", series(convertWebp, convertOtherImages, browserReloadFunc));
const compileJs = () =>
src("src/js/**/*.js")
.pipe(uglify())
.pipe(dest("dist/js"));
const watchJsFiles = () => watch("src/js/**/*.js", series(compileJs, browserReloadFunc));
exports.default = series(
compileEjs,
compileSass,
compileJs,
convertWebp,
convertOtherImages,
parallel(watchEjsFiles, watchSassFiles, watchJsFiles, watchImagesFiles, browserSyncFunc));