-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
55 lines (50 loc) · 1.52 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
var gulp = require("gulp");
var sass = require('gulp-sass');
var browserSync = require("browser-sync").create();
var useref = require("gulp-useref");
var uglify = require("gulp-uglify");
var gulpIf = require("gulp-if");
var cssnano = require("gulp-cssnano");
gulp.task("sass", function() {
return gulp
.src("app/scss/**/*.scss") // Gets all files ending with .scss in app/scss
.pipe(sass())
.pipe(gulp.dest("app/css"))
.pipe(
browserSync.reload({
stream: true
})
);
});
gulp.task("browserSync", function() {
browserSync.init({
server: {
baseDir: "app"
}
});
});
// gulp series /parallel introduced in gulp 4
// gulp task only takes two parameters, the task name and the call back
gulp.task("watch", gulp.parallel("browserSync", "sass", function() {
gulp.watch("app/scss/**/*.scss", gulp.series("sass"));
// Reloads the browser whenever HTML or JS files change
gulp.watch("app/*.html").on("change", browserSync.reload);
gulp.watch("app/js/*.js").on("change", browserSync.reload);
gulp.watch("app/js/**/*.js", browserSync.reload);
}));
gulp.task("fonts", function() {
return gulp.src("app/fonts/**/*").pipe(gulp.dest("dist/fonts"));
});
gulp.task("useref", function() {
return (
gulp
.src("app/*.html")
.pipe(useref())
// Minifies only if it's a JavaScript file
.pipe(gulpIf("*.js", uglify()))
.pipe(gulp.dest("dist"))
// Minifies only if it's a CSS file
.pipe(gulpIf("*.css", cssnano()))
.pipe(gulp.dest("dist"))
);
});