-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
74 lines (59 loc) · 1.61 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
/**
* Usage:
* Once per computer:
* npm install -g gulp
*
* Once per project:
* cd gulp-template
* npm install
* gulp
*
*/
// include gulp and all plugins
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
notify = require('gulp-notify'),
connect = require('gulp-connect'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
pixrem = require('gulp-pixrem');
// setup some variables with paths
var root = "./";
var css = {
src: root + "scss/index.scss",
watch: root + "scss/**/*.scss",
dest: root + "css/"
}
// create server with livereload
// chrome extension: https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en
gulp.task('connect', function(){
connect.server({
livereload: true,
root: root
});
});
// compile sass with all kinds of plugins
gulp.task('css', function(){
return gulp.src(css.src)
.pipe(plumber({errorHandler: onError}))
.pipe(sass())
.pipe(pixrem())
.pipe(autoprefixer())
.pipe(gulp.dest(css.dest))
.pipe(connect.reload()); // after everything is done, reload
});
// error handler that is passed to gulp-plumber
var onError = function(err) {
notify.onError({
title: "<%= error.plugin %>",
message: "<%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
// create watch task
gulp.task('watch', function(){
gulp.watch(css.watch, ['css']);
});
// default task (run when you run 'gulp')
gulp.task('default', ['connect', 'watch', 'css']);