-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
173 lines (160 loc) · 3.97 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
161
162
163
164
165
166
167
168
169
170
171
172
173
const { src, dest, watch, series, parallel } = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const sourcemaps = require("gulp-sourcemaps");
const plumber = require("gulp-plumber");
const notify = require("gulp-notify");
const fileinclude = require("gulp-file-include");
const autoprefixer = require("gulp-autoprefixer");
const bs = require("browser-sync").create();
const rimraf = require("rimraf");
const uglify = require("gulp-uglify");
const uglifycss = require("gulp-uglifycss");
// Paths
const path = {
src: {
html: "src/*.html",
others: "src/*.+(php|ico|png)",
htminc: "src/partials/**/*.htm",
incdir: "src/partials/",
vendor: "src/vendor/**/*.*",
fonts: "src/fonts/**/*.*",
js: "src/js/*.js",
scss: "src/scss/**/*.scss",
images: "src/images/**/*.+(png|jpg|gif|svg)",
blur: "src/images/**/*.jpg",
},
build: {
dir: "dist/",
},
};
// Clean Distribution folder
const clean = (cb) => {
rimraf("./dist", cb);
};
// Error Message
const customPlumber = (errTitle) => {
return plumber({
errorHandler: notify.onError({
// Customizing error title
title: errTitle || "Error running Gulp",
message: "Error: <%= error.message %>",
sound: "Glass",
}),
});
};
// HTML Task: Generate HTML files with partials
const html = () =>
src(path.src.html)
.pipe(customPlumber("Error Running html-include"))
.pipe(
fileinclude({
basepath: path.src.incdir,
})
)
.pipe(dest(path.build.dir))
.pipe(
bs.reload({
stream: true,
})
);
// SCSS Task: Generate Css files from .scss files
const scss = () =>
src(path.src.scss)
.pipe(customPlumber("Error Running Sass"))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write("/maps"))
.pipe(dest(path.build.dir + "css/"))
.pipe(
bs.reload({
stream: true,
})
);
const scssDev = () =>
src(path.src.scss)
.pipe(customPlumber("Error Running Sass"))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(uglifycss({ maxLineLen: 80, uglyComments: true }))
.pipe(autoprefixer())
.pipe(sourcemaps.write("/maps"))
.pipe(dest(path.build.dir + "css/"))
.pipe(
bs.reload({
stream: true,
})
);
// Javascript task: generate theme script files
const js = () =>
src(path.src.js)
.pipe(customPlumber("Error Running JS"))
.pipe(uglify())
.pipe(dest(path.build.dir + "js/"))
.pipe(
bs.reload({
stream: true,
})
);
// Assets Tasks: copy assets(images,vendor,fonts etc) from source to destination
const images = () =>
src(path.src.images)
.pipe(dest(path.build.dir + "images/"))
.pipe(
bs.reload({
stream: true,
})
);
const vendor = () =>
src(path.src.vendor)
.pipe(dest(path.build.dir + "vendor/"))
.pipe(
bs.reload({
stream: true,
})
);
const fonts = () =>
src(path.src.fonts)
.pipe(dest(path.build.dir + "fonts/"))
.pipe(
bs.reload({
stream: true,
})
);
const others = () =>
src(path.src.others)
.pipe(dest(path.build.dir))
.pipe(
bs.reload({
stream: true,
})
);
// Watch task
const watchTask = () => {
watch([path.src.html, path.src.htminc], series(html));
watch(path.src.scss, series(scss));
watch(path.src.js, series(js));
watch(path.src.images, series(images));
watch(path.src.vendor, series(vendor));
watch(path.src.fonts, series(fonts));
watch(path.src.others, series(others));
};
exports.default = series(
clean,
html,
parallel(scssDev, js),
parallel(images, vendor, fonts, others)
);
exports.dev = series(
html,
parallel(scss, js),
parallel(images, vendor, fonts, others),
parallel(watchTask, function () {
bs.init({
server: {
baseDir: path.build.dir,
},
port: 3050,
});
})
);