-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
73 lines (64 loc) · 1.57 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
const { watch, series, src, dest } = require("gulp");
var browserSync = require("browser-sync").create();
const concat = require('gulp-concat');
var postcss = require("gulp-postcss");
const imagemin = require("gulp-imagemin");
const uglify = require('gulp-uglify-es').default;
function cssTask(cb) {
return src("./src/css/*.css")
.pipe(postcss())
.pipe(concat('style.min.css'))
.pipe(dest("./src/css"))
.pipe(browserSync.stream());
cb();
}
function scriptsTask(cb) {
return src('./src/js/*.js')
.pipe(uglify())
.pipe(dest('./dist/js'))
.pipe(browserSync.stream());
cb();
}
// Task for minifying images
function imageminTask(cb) {
return src("./src/assets/images/**/*")
.pipe(imagemin())
.pipe(dest("./dist/assets/images"));
cb();
}
function htmlBuild(cb) {
return src("./src/*.html")
.pipe(dest("./dist"))
cb();
}
function browsersyncServe(cb) {
browserSync.init({
server: {
baseDir: "src/",
},
});
cb();
}
function browsersyncReload(cb) {
browserSync.reload();
cb();
}
// Watch Files & Reload browser after tasks
function watchTask() {
watch("./src/**/*.html", browsersyncReload);
watch(["./src/css/*.css"], series(cssTask, browsersyncReload));
watch(["./src/js/*.js"], series(scriptsTask, browsersyncReload));
}
function build() {
return src([
'src/css/style.min.css',
'src/assets/images/**/*',
'src/js/main.js',
'src/**/*.html ',
], {base: 'src'})
.pipe(dest('dist'))
}
exports.build = series(build);
exports.default = series(cssTask, scriptsTask, htmlBuild, browsersyncServe, watchTask);
exports.css = cssTask;
exports.images = imageminTask;