-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
58 lines (51 loc) · 1.41 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
"use strict";
const gulp = require("gulp");
const sass = require("gulp-sass");
const validator = require("gulp-html");
const del = require("del");
const useref = require("gulp-useref");
const uglify = require("gulp-uglify");
const cssnano = require("gulp-cssnano");
const gulpIf = require("gulp-if");
const brownserSync = require("browser-sync").create();
const files = {
sass: "./src/sass/**/*.scss",
fonts: "./src/fonts/**/*",
html: "./src/*.html",
js: "./src/js/**/*.js",
};
//Compiling SASS files
gulp.task("styles", () => {
return gulp
.src(files.sass)
.pipe(sass().on("error", sass.logError))
.pipe(gulp.dest("./src/css"))
.pipe(brownserSync.stream());
});
//Creating a hot serve
gulp.task("serve", () => {
brownserSync.init({
server: {
baseDir: "./src",
},
});
gulp.watch(files.sass, gulp.series(["styles"]));
gulp.watch(files.html).on("change", brownserSync.reload);
gulp.watch(files.js).on("change", brownserSync.reload);
});
//Cleaning the dist folder
gulp.task("clear", async () => {
await del("/dist/**");
});
//Validating, minifying and coping files to dist
gulp.task("build", () => {
gulp.src(files.fonts).pipe(gulp.dest("./dist/fonts"));
gulp
.src(files.html)
.pipe(useref())
.pipe(validator())
.pipe(gulpIf("*.js", uglify()))
.pipe(gulpIf("*.css", cssnano()))
.pipe(gulp.dest("./dist"));
});
gulp.task("default", gulp.series(["serve"]));