-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
77 lines (63 loc) · 2.12 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
74
75
76
77
// Required Node pluggins
var gulp = require('gulp'),
watch = require('gulp-watch'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
changed = require('gulp-changed'),
flatten = require('gulp-flatten'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
sass = require('gulp-sass'),
beeper = require('beeper');
// Project folders
var $ = {
src:{
root: './app',
sass:'./app/sass/**/*.sass',
js: './app/js/**/*.js',
html: './App/*.html'
},
dest:{
css:'./app/css/'
}
};
// Error handle function
var displayError = function(error) {
var errorString = '[' + error.plugin + ']';
errorString += ' ' + error.message.replace("\n",'');
if(error.fileName) {
errorString += ' in ' + error.fileName;
}
if(error.lineNumber) {
errorString += ' on line ' + error.lineNumber;
}
console.error( errorString );
beeper('*');
};
gulp.task('sass', function() {
gulp.src($.src.sass)
.pipe(plumber({errorHandler:function(err) { displayError(err); }}))
.pipe(sass({
indentedSyntax: true,
sourceComments: 'map',
sourceMap: 'sass',
outputStyle: 'nested' }))
.pipe(autoprefixer('last 2 version', '> 1%', 'ie 8', 'ie 9', 'ios 6', 'android 4'))
.pipe(flatten())
.pipe(changed($.dest.css, { extension: '.css', hasChanged: changed.compareSha1Digest }))
.pipe(gulp.dest($.dest.css))
.pipe(notify({title:'SAAS', message: '.......<%= file.relative %>'}));
});
// Run task and reload browser
gulp.task( 'sass-watch', ['sass'], browserSync.reload );
gulp.task( 'js-watch', browserSync.reload );
gulp.task( 'html-watch', browserSync.reload );
// Watch files for changes
gulp.task('default', function(){
// Create server
browserSync({ server: { baseDir: [$.src.root]}});
// Watch files
watch([$.src.sass], function() { gulp.start('sass-watch'); });
watch([$.src.html], function() { gulp.start('html-watch'); });
watch([$.src.js], function() { gulp.start('js-watch'); });
});