-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
115 lines (100 loc) · 2.94 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
111
112
113
114
115
/* globals require, exports */
'use strict';
// gulp plugins
var gulp = require('gulp'),
gutil = require('gulp-util'),
es = require('event-stream'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
jshint = require('gulp-jshint'),
coffee = require('gulp-coffee'),
clean = require('gulp-clean'),
connect = require('gulp-connect'),
browserify = require('gulp-browserify'),
usemin = require('gulp-usemin'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename');
// Connect Task
gulp.task('connect', connect.server({
root: ['./app'],
port: 1337,
livereload: true
}));
// Html reload
gulp.task('html', function () {
return gulp.src('./app/**/*.html')
.pipe(connect.reload());
});
// sass compiler task
gulp.task('sass', function () {
return gulp.src('./app/styles/**/*.scss')
.pipe(sass({
onError: function (error) {
gutil.log(gutil.colors.red(error));
gutil.beep();
},
onSuccess: function () {
gutil.log(gutil.colors.green('Sass styles compiled successfully.'));
}
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('./app/styles/'))
.pipe(connect.reload());
});
// Minify images
gulp.task('imagemin', function () {
return es.concat(
gulp.src('./app/images/**/*.png')
.pipe(imagemin())
.pipe(gulp.dest('/dest/img')),
gulp.src('./app/images/**/*.jpg')
.pipe(imagemin())
.pipe(gulp.dest('/dest/img')),
gulp.src('./app/images/**/*.gif')
.pipe(imagemin())
.pipe(gulp.dest('/dest/img'))
);
});
// CoffeeScript compiler task
gulp.task('coffee', function () {
return gulp.src('app/scripts/**/*.coffee')
.pipe(coffee({bare: true})).on('error', gutil.log)
.pipe(gulp.dest('app/scripts'));
});
// Script task
gulp.task('scripts', ['coffee'], function () {
return gulp.src('app/scripts/app.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(browserify({
insertGlobals: true
}))
.pipe(rename(function (path) {
path.basename = 'bundle';
}))
.pipe(gulp.dest('app/scripts'))
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch([ 'app/styles/**/*.scss'], ['sass']);
gulp.watch([ 'app/scripts' + '/**/*.js'], ['scripts']);
gulp.watch(['./app/**/*.html'], ['html']);
});
gulp.task('serve', ['connect', 'sass', 'scripts', 'watch']);
gulp.task('clean', function () {
gutil.log('Clean task goes here...');
});
gulp.task('usemin', function () {
gulp.src('./app/**/*.html')
.pipe(usemin())
.pipe(gulp.dest('./dist/'));
});
gulp.task('clean-build', function () {
return gulp.src('dist/', {read: false})
.pipe(clean());
});
gulp.task('build', ['clean-build', 'sass', 'scripts', 'imagemin', 'usemin'], function () {
});
gulp.task('default', function () {
gutil.log('Default task goes here...');
});