-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
36 lines (32 loc) · 1.13 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var cleanCSS = require('gulp-clean-css');
var autoprefixer = require('gulp-autoprefixer');
// Static Server + watching sass/html files
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "./"
});
gulp.watch("sass/*.sass", ['sass']);
gulp.watch("*.html").on('change', browserSync.reload);
});
// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
return gulp.src("css/*.sass")
.pipe(sourcemaps.init())
.pipe(sass()).on('error', function(err) {
console.error(err.message);
browserSync.notify(err.message, 3000); // Display error in the browser
this.emit('end'); // Prevent gulp from catching the error and exiting the watch process
})
.pipe(cleanCSS())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest("css"))
.pipe(browserSync.stream());
});
gulp.task('sass:watch', function () {
gulp.watch('./css/**/*.sass', ['sass']);
});
gulp.task('default', ['serve', 'sass:watch']);