-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (62 loc) · 1.94 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
const gulp = require('gulp');
const { watch, series, src, dest } = require("gulp");
var browserSync = require("browser-sync").create();
var postcss = require("gulp-postcss");
var fileinclude = require("gulp-file-include");
const imagemin = require("gulp-imagemin");
// Task for compiling our CSS files using PostCSS
function cssTask(cb) {
return src("./src/assets/css/*.css") // read .css files from ./src/ folder
.pipe(postcss()) // compile using postcss
.pipe(dest("./public/assets/css")) // paste them in ./assets/css folder
.pipe(browserSync.stream());
cb();
}
// Task for minifying images
function imageminTask(cb) {
return src("./src/assets/images/*")
.pipe(imagemin())
.pipe(dest("./public/assets/images"));
cb();
}
// Task for file includes
function fileincludeTask(cb) {
return src(['./src/*.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('./public'))
.pipe(browserSync.stream());
cb();
}
// Task for fonts
function fontsTask(cb) {
return src("./src/assets/fonts/*")
.pipe(dest("./public/assets/fonts"));
cb();
}
// Serve from browserSync server
function browsersyncServe(cb) {
browserSync.init({
server: {
baseDir: "./public/",
},
});
cb();
}
function browsersyncReload(cb) {
browserSync.reload();
cb();
}
// Watch Files & Reload browser after tasks
function watchTask() {
watch(["./src/assets/images/*"], series(imageminTask, browsersyncReload));
watch(["./src/**/*.css"], series(cssTask, browsersyncReload));
watch(["./src/**/*.html"], series(fileincludeTask, browsersyncReload));
}
// Default Gulp Task
exports.default = series(fileincludeTask, cssTask, fontsTask, imageminTask, browsersyncServe, watchTask);
exports.css = cssTask;
exports.images = imageminTask;
exports.build = series(fileincludeTask, cssTask, fontsTask, imageminTask);