-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
93 lines (78 loc) · 2.64 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
/********************************************************************************
Importing modules
********************************************************************************/
var gulp = require('gulp'),
concat = require('gulp-concat')
uglify = require('gulp-uglify'),
jsValidate = require('gulp-jsvalidate'),
sass = require('gulp-sass'),
plumber = require('gulp-plumber'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
/********************************************************************************
Paths
********************************************************************************/
scssPath = {'from':'src/scss/**/*.scss','to':'public/css'},
jsPath = {'from':'src/js/**/*.js','to':'public/js'},
phpPath = {'from':'src/**/*.php','to':'public'};
/********************************************************************************
Task's list
********************************************************************************/
// Scripts task
gulp.task('jsScripts',function()
{
gulp.src ( jsPath.from )
.pipe( plumber({errorHandler: displayError}) )
.pipe( jsValidate() )
.pipe( concat('main.js') )
.pipe( uglify() )
.pipe( gulp.dest( jsPath.to ) )
.pipe( reload({stream:true}) );
});
// Scss task
gulp.task('scss',function()
{
gulp.src ( scssPath.from )
.pipe( plumber({errorHandler: displayError}) )
.pipe( concat('style.css') )
.pipe( sass())
.pipe( gulp.dest( scssPath.to ) )
.pipe( reload({stream:true}) );
});
// Php task
gulp.task('phpFiles',function()
{
gulp.src ( phpPath.from )
.pipe( gulp.dest( phpPath.to ) )
.pipe( reload({stream:true}) );
});
// BrowserSync task
gulp.task('browser-sync', function()
{
browserSync({
port:8888,
proxy: "localhost"
});
});
// Watching files and triggering tasks
gulp.task('watch', function()
{
gulp.watch( jsPath.from ,['jsScripts'] );
gulp.watch( scssPath.from ,['scss'] );
gulp.watch( phpPath.from ,['phpFiles'] );
});
// Default task's list
gulp.task('default',['jsScripts','scss','phpFiles','browser-sync','watch']);
//Custom error display for plumber
var displayError = function(error)
{
// Initial building up of the error
var errorString = '[' + error.plugin + ']';
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
errorString += ' in ' + error.fileName || "";
errorString += ' on line ' + error.lineNumber || "";
// This will output an error like the following:
// [gulp-sass] error message in file_name on line 1
console.error(errorString);
}