-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (82 loc) · 2.52 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
gulpif = require('gulp-if'),
compass = require('gulp-compass'),
uglify = require('gulp-uglify'),
minifyHTML = require('gulp-minify-html'),
jsonminify = require('gulp-jsonminify'),
connect = require('gulp-connect'),
concat = require('gulp-concat');
var env,
jsSources,
sassSources,
htmlSources,
jsonSources,
outputDir,
sassStyle;
env = process.env.NODE_ENV || 'development';
if (env==='development') {
outputDir = 'builds/development/';
sassStyle = 'expanded';
} else {
outputDir = 'builds/production/';
sassStyle = 'compressed';
}
jsSources = [
'assets/js/services/*.js',
'assets/js/controllers/*.js',
'assets/js/app.js'
];
sassSource = ['assets/css/main.scss'];
htmlSources = ['builds/development/views/*.html'];
jsonSources = [outputDir + 'js/*.json'];
gulp.task('js', function() {
gulp.src(jsSources)
.pipe(concat('script.js'))
.pipe(gulpif(env === 'production', uglify()))
.pipe(gulp.dest(outputDir + 'assets/js'))
.pipe(connect.reload())
});
gulp.task('html', function() {
gulp.src('builds/development/*.html')
.pipe(gulpif(env === 'production', minifyHTML()))
.pipe(gulpif(env === 'production', gulp.dest(outputDir)))
.pipe(connect.reload())
});
gulp.task('views', function() {
gulp.src('builds/development/views/*.html')
.pipe(gulpif(env === 'production', minifyHTML()))
.pipe(gulpif(env === 'production', gulp.dest(outputDir + 'views')))
});
gulp.task('compass', function() {
gulp.src(sassSource)
.pipe(compass({
style: sassStyle,
image: 'builds/development/assets/img',
sass: 'assets/css',
css: outputDir + 'assets/css'
})
.on('error', gutil.log))
.pipe(gulp.dest(outputDir + 'assets/css'))
.pipe(connect.reload())
});
gulp.task('watch', function() {
gulp.watch('assets/js/**/*.js', ['js']);
gulp.watch('assets/css/**/*', ['compass']);
gulp.watch('builds/development/*.html',['html']);
gulp.watch(outputDir + 'assets/css/main.css',['html']);
gulp.watch('builds/development/views/*.html',['views']);
});
gulp.task('json', function() {
gulp.src('builds/development/js/*.json')
.pipe(gulpif(env === 'production', jsonminify()))
.pipe(gulpif(env === 'production', gulp.dest('builds/production/js')))
.pipe(connect.reload())
});
gulp.task('connect', function() {
connect.server({
root: outputDir,
livereload: true
});
});
gulp.task('default', ['html', 'views', 'json', 'js', 'compass', 'connect', 'watch']);