-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
93 lines (84 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
var gulp = require('gulp'),
postcss = require('gulp-postcss'),
sourcemaps = require('gulp-sourcemaps'),
prefix = require('autoprefixer'),
colors = require('gulp-util').colors,
concat = require('gulp-concat'),
csso = require('gulp-csso'),
jade = require('gulp-jade'),
uglify = require('gulp-uglify'),
lost = require('lost'),
livereload = require('gulp-livereload'),
tinylr = require('tiny-lr'),
sass = require('gulp-sass'),
server = tinylr();
tasks = ['js','css', 'watch', 'templates'];
var paths = {
cssSource: 'assets/sass/',
cssDestination: 'build/css/',
jsSource: 'assets/js/',
jsDestination: 'build/js/',
htmlSource: 'app/views/'
};
// ---------------------------------------
// Watch Task
// ---------------------------------------
gulp.task('default', tasks);
gulp.task('compile', ['js','css']);
console.log(colors.green('======================================================='));
console.log(colors.green('Start tasks'));
console.log(colors.green('======================================================='));
// ---------------------------------------
// Styling
// ---------------------------------------
gulp.task('css', function() {
return gulp.src(paths.cssSource + '**/*.scss')
.pipe(
sass({
includePaths: [paths.cssSource + '**/*'],
errLogToConsole: true
})
)
.pipe(
postcss([
prefix({
browsers: ['last 2 versions']
}),
lost()
])
)
.pipe( csso() )
.pipe( gulp.dest(paths.cssDestination) )
.pipe( livereload( server ));
});
// ---------------------------------------
// Scripts
// ---------------------------------------
gulp.task('js', function() {
return gulp.src(paths.jsSource + '**/*.js')
.pipe( uglify() )
.pipe( concat('main.min.js'))
.pipe( gulp.dest(paths.jsDestination))
.pipe( livereload( server ));
});
// ---------------------------------------
// Templates
// ---------------------------------------
gulp.task('templates', function() {
return gulp.src(paths.htmlSource + '*.jade')
.pipe( livereload( server ));
});
// ---------------------------------------
// Watch
// ---------------------------------------
gulp.task('watch', function () {
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
gulp.watch(paths.cssSource + '**/*.scss',['css']);
gulp.watch(paths.jsSource + '**/*.js',['js']);
gulp.watch(paths.htmlSource + '*.jade',['templates']);
gulp.watch('app/data.js',['templates']);
});
});