-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
110 lines (93 loc) · 2.63 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var gulp = require('gulp'),
pug = require('gulp-pug'),
prefix = require('gulp-autoprefixer'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
minifyCSS = require('gulp-minify-css'),
cleanCSS = require('gulp-clean-css'),
notify = require('gulp-notify'),
concat = require('gulp-concat'),
path = require('path'),
rename = require('gulp-rename');
var paths = {
public: './dist/',
sass: './src/scss/',
css: './dist/css/',
data: './src/_data/',
pug: './src/*.pug'
};
var prefixerOptions = {
browsers: ['last 2 versions']
};
var sassOptions = {
outputStyle: 'compressed'
};
var displayError = function(error) {
// Initial building up of the error
var errorString = '[' + error.plugin.error.bold + ']';
errorString += ' ' + error.message.replace("\n",''); // Removes new line at the end
// If the error contains the filename or line number add it to the string
if(error.fileName)
errorString += ' in ' + error.fileName;
if(error.lineNumber)
errorString += ' on line ' + error.lineNumber.bold;
// This will output an error like the following:
// [gulp-sass] error message in file_name on line 1
console.error(errorString);
};
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Basso"
})(err);
this.emit('end');
};
/* SCSS
---------------------------------------------*/
gulp.task('sass', function (){
return gulp.src(paths.sass + 'main.scss')
.pipe(sass())
.pipe(sass(sassOptions))
.pipe(prefix(prefixerOptions))
.pipe(concat('main.css'))
.pipe(cleanCSS())
.pipe(rename('main.min.css'))
.pipe(gulp.dest(paths.css));
});
/* PUG
---------------------------------------------*/
gulp.task('pug',function (){
return gulp.src(paths.pug)
.pipe(pug({
pretty: true
}))
.on('error', notify.onError(function (error) {
return 'An error occurred while compiling pug.\nLook in the console for details.\n' + error;
}))
.pipe(gulp.dest(paths.public));
});
gulp.task('rebuild', ['pug', 'sass'], function () {
browserSync.reload();
});
gulp.task('browser-sync', ['sass', 'pug'], function () {
browserSync({
server: {
baseDir: paths.public
},
notify: false
});
});
/* WATCH
---------------------------------------------*/
gulp.task('watch', function (){
gulp.watch(paths.sass + '**/*.scss',['sass']);
gulp.watch('./src/**/*.pug', ['rebuild']);
});
/* BUILD
---------------------------------------------*/
gulp.task('build', ['sass', 'pug']);
/* BROWSER SYNC
---------------------------------------------*/
gulp.task('default', ['browser-sync', 'watch']);